Skip to content

util: use indexed writes for inspected object properties - #67297

Open
rozzilla wants to merge 1 commit into
nodejs:mainfrom
rozzilla:perf-util-inspect-object-props
Open

rozzilla wants to merge 1 commit into
nodejs:mainfrom
rozzilla:perf-util-inspect-object-props

Conversation

@rozzilla

@rozzilla rozzilla commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Similar improvement to the one merged here: #66872

Use indexed writes instead of primordial push calls when collecting formatted own and extra properties in formatRaw(). This loop runs for every inspected object with own keys.

In local benchmarks on Apple M2/macOS, inspecting a 50-key object improved throughput by 9.7%. Unaffected string and array controls showed no significant change.

Avoid the cost of primordial push calls for each formatted property.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Nov 6, 2026
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.67%. Comparing base (fca40eb) to head (e2ccae9).
⚠️ Report is 60 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67297      +/-   ##
==========================================
- Coverage   93.00%   90.67%   -2.34%     
==========================================
  Files         428      797     +369     
  Lines      195754   279605   +83851     
  Branches    30290    53779   +23489     
==========================================
+ Hits       182054   253518   +71464     
- Misses      13374    16358    +2984     
- Partials      326     9729    +9403     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 97.04% <100.00%> (+20.97%) ⬆️

... and 505 files with indirect coverage changes

🚀 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.

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

imo we should always be doing this over push, but cc @BridgeAR since i thought they'd told me that push tends to be faster, benchmark notwithstanding?

@gurgunday

Copy link
Copy Markdown
Member

@ljharb I agree and no it’s no longer the case that push is faster

arr[arr.length] = x no longer transitions an array from PACKED to HOLEY. It is always as fast or faster (especially compared to primordials) in my tests on all active Node releases now

honestly i would prefer one pr that moves all the instances and maybe even an eslint rule

@gurgunday gurgunday added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 10, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 10, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants