Conversation
|
Here's relevant jsperf: https://jsperf.com/for-loop-vs-array-prototype-map-bench |
There was a problem hiding this comment.
I doubt the JSPerf is representative here, because there are significant differences — 1) the number of coordinates is usually very low (e.g. 6 tiles is typical for a full-screen map), vs 10000 in the bench; 2) arrays of objects like in this case have very different perf characteristics than arrays of numbers, which are treated differently by JS engines. 3) Microbenchmarks can be misleading — e.g. 1, 2.
Unless you can demonstrate measurable performance difference in GL JS specifically, I'd be inclined to keep the code more terse and simple.
|
Wonder why that function took longest scripting time inside Chrome dev tools performance tab, and after this I got it down to like 10th. I try to run some benchmarks with and without. |
|
Didn't realize the arrays are so small, so you're probably right! Maybe need to profile getRenderableIds instead.. 🤔 |
The profiling results often fluctuate depending on what's happening in the background, what exactly you did during the profiling, etc. Here's a quick result I got zooming/panning for a few seconds: |
|
Yeah, that might be the case – i'll keep on investigating, thanks! 😎 |
|
@pakastin it's interesting that you raised this because I've also noticed I don't have a solution but I agree that it might be worth investigating. |
|
Yeah, I too have quite many layers here: I was wondering did I really profile so wrong 😄 |
|
Well, this PR would make it faster when there’s many iterables.. 😎 |
|
Yeah, in some other circumstances that would be just micro-optimization, but when you have constant 60 fps budget, every fraction of a millisecond counts.. |
|
I've also made a similar change as a part of #7971 — can you check this one too? |
|
I've been testing this by panning a pitched satellite map around for a few seconds and I'm unable to see any significant performance improvement relative to master. Dev tools is telling me that almost all of the time is spent on @asheemmamoowala do you mean to say that the pitched map reduces performance relative to a flat map? Or that this PR increases performance relative to master? |
The fix here improves performance relative to master, i.e. it reduces the time spent in |
|
It’s almost impossible that it would be slower after optimizations, since for-loop does less than array prototype methods. |



I started to profile panning/zooming performance and realized
getVisibleCoordinatesfunction is pretty heavy. Preallocating an array and using a single for-loop while addingposMatrixsimultaneously makes it faster.