Repository navigation
Report fewer progress steps when formatting JS code - #6520
Merged
Merged
Conversation
Each progress message makes the main thread apply the format edits to the whole code and replace the source view contents, which makes CodeMirror parse again for up to 20ms. Each step also walks the syntax tree from the start. So each step now parses for at least 16 times as long as the last walk took, instead of 4 times. For a 3.4MB minified bundle in Firefox, this reduces the progress messages from 6 to 3, and the main thread time spent handling them from about 250ms to about 140ms. The code is fully formatted about 160ms sooner, and the first formatted code shows up as early as before.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the adjustment to JavaScript-formatting progress timing.
No open issues 🎉
What changed in this PR
Reduces JavaScript-formatting progress updates to cut repeated syntax-tree walks and source-view rebuilds.
Changes:
- Raises the adaptive parse-time multiplier from 4 to 16, retaining the 50 ms minimum.
- Introduces a named constant and documents the performance trade-off.
| File | Description |
|---|---|
src/profile-logic/js-format/formatter.ts |
Adjusts and documents adaptive formatting progress timing. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6520 +/- ##
=======================================
Coverage 85.22% 85.22%
=======================================
Files 372 372
Lines 40786 40787 +1
Branches 11686 11691 +5
=======================================
+ Hits 34760 34761 +1
Misses 5586 5586
Partials 440 440 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Main | Deploy preview
Each progress message from the format worker is expensive on the main thread. The main thread applies the edits to the whole code, and replacing the source view contents makes CodeMirror parse again for up to 20ms. Each step also walks the syntax tree from the start in the worker. Right now each step parses for 4 times as long as the last walk took, which gives 6 steps for a large bundle. This PR raises the factor to 16.
Results for a 3.4MB minified bundle in Firefox:
The first formatted code shows up as early as before (~115ms after the click, including the worker startup). Files below ~1MB already finished in 2-4 steps, so nothing changes for them. The trade-off is fewer intermediate updates while a large file is formatted. The final edits are identical in both cases.