-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Overhaul of RTL plugin loading sequence #3728
Conversation
I'm not sure I fully understand the change in this PR. |
I see. Thanks for the info!
It would be super! |
Very interesting tool --- did not know it exists --- quite helpful and now it is clear that my previously proposed change can be optimized further. I think 3.6.1 and old were confusing as hell because at certain times Mapbox was probably running these on both main and worker, correct? |
Yes, I agree, the original code was running in both main thread and in the worker, I have split the code to improve readability and maintainability.
Which ever you find more intuitive for you. |
Proposed new design --- inevitably it is more complicated than I initially thought, because it must solve a race condition between Tile (calling lazyLoadRTLTextPlugin) and the hosting app (calling setRTLTextPlugin), and ensure the same outcome regardless of whichever happens first. |
Can you draw a state machine chart with the new/updated states? |
Second thought, keep loading state is better. |
Thanks for the updated diagram! |
Draft ready. Will publish the PR and write test cases if you don't see anything fundamentally wrong. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3728 +/- ##
===========================================
- Coverage 86.59% 70.90% -15.70%
===========================================
Files 240 240
Lines 32289 32336 +47
Branches 1952 1202 -750
===========================================
- Hits 27962 22928 -5034
- Misses 3399 8206 +4807
- Partials 928 1202 +274 ☔ View full report in Codecov by Sentry. |
Go ahead. Ping me when you set it to ready for review as GitHub doesn't notify me on this change. |
@zhangyiatmicrosoft any updates on this? |
In addition, I found that MapLibre is using strings for status everywhere, for example: From other code bases I learned const enum is far better, such as:
If you agree I'd like to change most of statues to const enum, one at time, starting from RTLPluginStatus in this PR |
Note that there are lint warnings in last commit related to unused imports, should be a few sec to fix I believe. |
* all UT * UT * Add FT
lint problem fixed |
I don't have write access anymore. Can some please merge. Thanks |
Launch Checklist
Symptom: we were previously using 3.6.1 and recently tried to upgrade to 4.x, and noticed that map load speed is slowed down by 50ms at percentile 90. I found that it took one or two extra frames when setRTLTextPlugin is called before map creation, based on official instruction: https://maplibre.org/maplibre-gl-js/docs/examples/mapbox-gl-rtl-text/.
This problem appears to be introduced by PR #3418
The following diagrams apply when the app calls setRTLTextPlugin for the very first time and "deferred" parameter is true
3.6.1
4.0.2 (after PR #3418), notice 2, 3, 4 were not there in 3.6.1
The "broadcasting-reload" cycle is done twice (loading, loaded) when lazyLoadRTLTextPlugin is called and it is downloading the plugin. Only one is enough.
This PR
State diagram -- add "requested" state, so they are:
'unavailable' | 'deferred' | 'requested' | 'loading' | 'loaded' | 'error'
Cosmetic changes to improve readability/robustness/performance:
symbol_bucket.ts: once RTL is detect for this bucker, all future detections can be skipped
index.ts: formatting for reading pleasure
rtl_text_plugin_status.ts: define event name and message name to be used by other files
worker.ts to respond with PluginState object instead of boolean, which can be too ambiguous to process
worker_tile.ts: formatting and commenting for readability
ajax.ts: I personally found nested tertiary operations are really hard to read and error prone. Made them to simple "if". The minimizer will do its job and end result will be the same anyway.
Some method names are shortened
Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
Briefly describe the changes in this PR.
Link to related issues.
Include before/after visuals or gifs if this PR includes visual changes.
Write tests for all new functionality.
Add an entry to
CHANGELOG.md
under the## main
section.