Commit fce7e24
perf: Speed up
[As reported on Slack](https://academysoftwarefdn.slack.com/archives/C05782U3806/p1751642730171029),
between OIIO 2.5 and 3.0, we had a big slowdown when doing a
multithreaded `maketx --envlatl`, which was traced almost entirely to
the new mutex lock in ImageBuf::IteratorBase::init_ib(), which were all
happening inside the call stack of `resize_block_<float>()`.
The reason was that it was calling ImageBuf::interppixel_NDC for every
pixel, which in turn works by creating (internally) an
ImageBuf::ConstIterator to sample the 4 nearby pixels. But every one of
those ConstIterator constructors called init_ib, which briefly grabbed
the mutex for the IB, which in addition to being wasteful on its own,
caused the threads to block on each other.
The solution is straightforward: there is no need to construct a new
Iterator for every pixel. We can create the iterator once (a single call
to the init_ib for each thread region of the image) and then for each
pixel, just call its `rerange()` method to reset the set of pixels to
loop over for the samples needed for that pixel.
I also opportunistically eliminated a few redundant spec() calls in
various routines in imagebuf.cpp.
On my Mac laptop, when doing a maketx --latlong on a 16k image with 16
threads, it was previously taking 170.5s (including 117.8s for the
initial resize and 42.8s for the MIP computations). With this change,
the same operation takes 12.4s (including 3.7s for the initial resize
and 1.6s for he MIP computations). That's almost a 14x speedup. YMMV,
depending on platform, compiler, image size, and number of threads.
Signed-off-by: Larry Gritz <[email protected]>maketx --envlatl when multithreaded by over 10x. (AcademySoftwareFoundation#4825)1 parent 5adf63c commit fce7e24
2 files changed
+35
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2961 | 2961 | | |
2962 | 2962 | | |
2963 | 2963 | | |
2964 | | - | |
| 2964 | + | |
| 2965 | + | |
2965 | 2966 | | |
2966 | 2967 | | |
2967 | 2968 | | |
| |||
2977 | 2978 | | |
2978 | 2979 | | |
2979 | 2980 | | |
2980 | | - | |
| 2981 | + | |
| 2982 | + | |
2981 | 2983 | | |
2982 | 2984 | | |
2983 | 2985 | | |
| |||
2993 | 2995 | | |
2994 | 2996 | | |
2995 | 2997 | | |
2996 | | - | |
| 2998 | + | |
| 2999 | + | |
2997 | 3000 | | |
2998 | 3001 | | |
2999 | 3002 | | |
| |||
3009 | 3012 | | |
3010 | 3013 | | |
3011 | 3014 | | |
3012 | | - | |
| 3015 | + | |
| 3016 | + | |
3013 | 3017 | | |
3014 | 3018 | | |
3015 | 3019 | | |
| |||
3025 | 3029 | | |
3026 | 3030 | | |
3027 | 3031 | | |
3028 | | - | |
| 3032 | + | |
| 3033 | + | |
3029 | 3034 | | |
3030 | 3035 | | |
3031 | 3036 | | |
| |||
3041 | 3046 | | |
3042 | 3047 | | |
3043 | 3048 | | |
3044 | | - | |
| 3049 | + | |
| 3050 | + | |
3045 | 3051 | | |
3046 | 3052 | | |
3047 | 3053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
143 | 144 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | | - | |
| 153 | + | |
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
| |||
160 | 162 | | |
161 | 163 | | |
162 | 164 | | |
163 | | - | |
164 | | - | |
| 165 | + | |
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
| |||
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
184 | | - | |
185 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| |||
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
221 | 227 | | |
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 232 | + | |
| 233 | + | |
230 | 234 | | |
231 | 235 | | |
232 | 236 | | |
| |||
311 | 315 | | |
312 | 316 | | |
313 | 317 | | |
314 | | - | |
| 318 | + | |
315 | 319 | | |
316 | 320 | | |
317 | 321 | | |
| |||
387 | 391 | | |
388 | 392 | | |
389 | 393 | | |
| 394 | + | |
390 | 395 | | |
391 | 396 | | |
392 | 397 | | |
393 | 398 | | |
394 | 399 | | |
395 | 400 | | |
396 | 401 | | |
397 | | - | |
398 | | - | |
| 402 | + | |
| 403 | + | |
399 | 404 | | |
400 | 405 | | |
401 | 406 | | |
| |||
0 commit comments