-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Improve image/glyph atlas packing algorithm #7171
Conversation
Awesome @mourner ! A good place to test is around here - rotate and pan to load as many tiles as possible! |
@bhousel I ran some modified benchmarks from ShelfPack that stress the "low height variation" case (with |
46fa816
to
46836aa
Compare
@mourner the As part of #7207, however, we may need to be able to modify/add sprites to these |
@mollymerp great! I'll push the Quick question — one render test ( |
This is now ready for review. |
@@ -75,6 +74,7 @@ | |||
"pngjs": "^3.0.0", | |||
"postcss-cli": "^5.0.0", | |||
"postcss-inline-svg": "^3.1.1", | |||
"potpack": "^1.0.1", |
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 this be a regular dependency rather than a dev dependency?
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.
Yeah, my misstep, although it actually doesn't affect anything because GL JS is only usable with the built bundle. We might want to move most other regular deps to devdeps then.
Since our current binpacking uses are mostly static, I found a simple packing algorithm that produces smaller glyph and image atlases than
shelf-pack
— for a typical streets z11 view, about 20% less pixels in average. This may not be reflected noticeably on the benchmarks, but it means textures will use less memory and be faster to upload to GPU on tile loads.In this PR, I've only switched worker-side atlases to the new packing since they're fully static. The next step would be to replace
shelf-pack
inimage_manager.js
for currently used patterns, but that would mean replacing dynamic insertion/removal of individual images with repacking all patterns every time one is added/removed. This may be fine because there are only a couple patterns on the screen at a time on typical styles, not thousands where it could be perf a problem.If the approach sounds OK, I can work on this further and also likely publish the algorithm as a separate ES module.
shelf-pack
would still remain our module of choice for dynamic use cases.cc @jfirebaugh @bhousel
Benchmarks
Launch Checklist
write tests for all new functionalitydocument any changes to public APIs