-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid XHR when possible for faster raster tile loading #7008
Conversation
src/util/ajax.js
Outdated
} | ||
img.onload = () => callback(null, img); | ||
img.src = url; | ||
return {cancel: () => { img.src = transparentPngUrl; }}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't callback(err)
be handled here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an onerror handler would solve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, added.
Ran |
3e19947
to
f3f9357
Compare
XHR heuristics works perfectly, both cases are working well. |
What are you using to evaluate this versus the prior behavior? In light testing, I'm not sure I can distinguish the difference. |
@jfirebaugh I'm using the original test case here https://codesandbox.io/s/zl761nnr3m — the difference is very noticeable, especially if you have #6995 (another big perf hit) pulled in when comparing. |
Here is a source with short expires time:
And Mapbox satellite for example is with long expires time. |
@jfirebaugh make sure you don't have developer tools open, as that introduced janks for me in Chrome. old: https://codesandbox.io/s/zl761nnr3m |
This is with developer tools closed. Subjectively, the behavior I see is:
|
@jfirebaugh on the examples above (make sure both are viewed fullscreen), I get heavy stuttering on the old example (on my MBP Retina 15'' screen), especially in the middle of zooming in and zooming out, and almost no jank on the new one. Perf recording before ( After ( I also noticed like @hyperknot that it still stutters when devtools are open, but stops stuttering when you start recording a timeline perf profile — I guess Chrome disables some debug stuff while recording. |
Yeah, I don't see results as definitive as that. I'm testing locally with this file: https://gist.github.com/jfirebaugh/7cf3e57c359513f980d6aad56283d75e. I wonder what causes such different results for us? |
f3f9357
to
bbbea02
Compare
@jfirebaugh I think it's important to have all the other raster perf PRs merged in for this to have pronounced effect. I just rebased both PRs (this and #6995) on master. Now can you compare this PR vs this PR + #6995 merged? |
I've been testing with Does someone else want to step in and try? Must be some other variable unaccounted for here. |
I've ported the example to OpenLayers, with a similar animation (the easing is different). https://611v4nk57z.codesandbox.io/ |
98aa79b
to
471c785
Compare
471c785
to
8a0da8f
Compare
@hyperknot @jfirebaugh I just pushed a new WIP branch based on this one that adds a basic image queue (cbb059f), limiting parallel image loads to 16 at a time. Can you try it out and see if it makes a difference for performance? |
@hyperknot any comment on the above? |
@hyperknot the last release includes all improvements except this PR (avoiding XHR for image loading). And additionally cbb059f explores the concept of limiting concurrency for image loads — let's see if it's any faster than this branch. |
@mourner OK, I'll check out the improvements and report back today. |
@hyperknot any updates? |
Oh, sorry, I promised to get back but I didn't. I'll do it now. |
@mourner this is absolutely wonderful performance wise! The 2 fps parts are now totally gone, even with console open. I did a comparison between 0.50 and cbb059f here: My only problem now is that I'm yet 100% confident in how the code is implemented. What isn't clear is both handleImageLoad and getImage checks for Also, are you sure it can never happen that the queue explodes? I mean getImage adds handlers for handleImageLoad which calls getImage. Having said that, if all the delicate parts of these are thought out by you then I'm happy with the added huge performance improvements! |
@hyperknot awesome, thanks a lot for checking! This was a quick proof of concept so likely pretty buggy — and now since this seems promising, I'll probably explore it more. Note that while FPS is improved, the branch codepen version seems to have more blurry tiles when zooming in because new ones aren't loaded fast enough. We're also exploring raster loading performance from another angle in #7405, which will hopefully bring more improvements too. |
But blurry tiles are good, aren't they? I mean blurry means that smooth
animation is more important than title loading, which is exactly what
should happen.
Maybe it can be polished so that the tiles at the center of the screen take
higher priority then the ones at the edges though.
…On 2018. Oct 18., Thu at 18:13, Vladimir Agafonkin ***@***.***> wrote:
@hyperknot <https://github.com/hyperknot> awesome, thanks a lot for
checking! This was a quick proof of concept so likely pretty buggy — and
now since this seems promising, I'll probably explore it more. Note that
while FPS is improved, the branch codepen version seems to have more blurry
tiles when zooming in because new ones aren't loaded fast enough.
We're also exploring raster loading performance from another angle in
#7405 <#7405>, which will
hopefully bring more improvements too.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7008 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAeKj4LsKGQa0-vNd1V-gytd1zjV47k8ks5umKjFgaJpZM4VasEq>
.
|
OK, I had some proper look again, at how is blurriness handled, and found some interesting discoveries.
I was using this custom profile in NLC (and "Online" in the browser), it was really good to test this behaviour: As the difference in behaviour is extremely big, I even recommend making a universal tile queue and use it for vector tiles as well maybe? This is something which we never see when developing on reliable network connections but mobile clients in the real world can have really high packet losses. |
I can confirm that cbb059f is much smoother on my computer as well. It seems to load the maximum number of image loads that are loaded in parallel. However, I'm still seeing more than one image per frame being uploaded (call to |
@hyperknot thank you for these wonderful test cases; they're very useful for debugging this issue! |
I have a feeling this PR won’t have much effect after #7497, so I’m going to close for now. |
A proposal for addressing #6643. If we see that a raster tile we requested with XHR should be cached for a long time (currently set to 1 hr), we switch from XHR to simple
new Image
tile loads for that source. This fixes a lot of the jank when using raster tile sources.Launch Checklist
write tests for all new functionality(we don't have tests for image loading, and they probably won't be useful anyway as long as we usejsdom
and stubbing)document any changes to public APIs