Skip to content

Report fewer progress steps when formatting JS code - #6520

Merged
canova merged 1 commit into
firefox-devtools:mainfrom
canova:fewer-format-updates
Dec 4, 2026
Merged

canova merged 1 commit into
firefox-devtools:mainfrom
canova:fewer-format-updates

Conversation

@canova

@canova canova commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

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:

main this PR
Progress messages 6 3
Main thread time handling them ~250ms ~140ms
Click to fully formatted ~1450ms ~1290ms
Worker CPU time ~1320ms ~1150ms

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.

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.
@canova
canova requested review from mstange and a balanced review from Copilot December 4, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.22%. Comparing base (bcc5a09) to head (c5c1920).
⚠️ Report is 20 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mstange mstange left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@canova
canova added this pull request to the merge queue Dec 4, 2026
Merged via the queue into firefox-devtools:main with commit d1be5b9 Dec 4, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants