Skip to content

src: reserve simdjson padding in parsePackageJSON - #67623

Open
lemire wants to merge 1 commit into
nodejs:mainfrom
lemire:src-reserve-simdjson-padding
Open

lemire wants to merge 1 commit into
nodejs:mainfrom
lemire:src-reserve-simdjson-padding

Conversation

@lemire

@lemire lemire commented Nov 19, 2026

Copy link
Copy Markdown
Member

The parsePackageJSON() function copies its input into a std::string with no spare
capacity. The simdjson::pad() function then appends SIMDJSON_PADDING spaces.
This change reserves room for the padding when the input is copied, so the append happens in
place.

This adds benchmark/module/parse-package-json.js, which parses the
unique package.json files under deps/, grouped by file size.

Benchmarks

benchmark/compare.js, 30 runs, old = main (108cbef), new = this PR,
Welch's t-test.

Intel Xeon Gold 6548N (Emerald Rapids), Linux, clang 23:

                                                    confidence  improvement  accuracy (*)    (**)   (***)
module/parse-package-json.js n=1000000 size='0-512'        ***        6.94 %       ±0.84%  ±1.13%  ±1.47%
module/parse-package-json.js n=1000000 size='512-1024'     ***        9.98 %       ±2.55%  ±3.39%  ±4.41%
module/parse-package-json.js n=1000000 size='1024-2048'    ***        9.97 %       ±3.00%  ±3.99%  ±5.20%
module/parse-package-json.js n=1000000 size='2048+'         **        6.72 %       ±4.83%  ±6.43%  ±8.37%

Intel Xeon Gold 6338 (Ice Lake), Linux, clang 23:

                                                    confidence  improvement  accuracy (*)    (**)   (***)
module/parse-package-json.js n=1000000 size='0-512'        ***        5.52 %       ±0.43%  ±0.58%  ±0.76%
module/parse-package-json.js n=1000000 size='512-1024'     ***       11.12 %       ±0.37%  ±0.49%  ±0.64%
module/parse-package-json.js n=1000000 size='1024-2048'    ***       11.48 %       ±0.41%  ±0.54%  ±0.70%
module/parse-package-json.js n=1000000 size='2048+'        ***        9.42 %       ±0.35%  ±0.46%  ±0.60%

Apple M4 Max, macOS, Apple clang 17:

                                                    confidence  improvement  accuracy (*)    (**)   (***)
module/parse-package-json.js n=1000000 size='0-512'        ***       10.13 %       ±0.98%  ±1.30%  ±1.69%
module/parse-package-json.js n=1000000 size='512-1024'     ***        9.52 %       ±0.77%  ±1.03%  ±1.34%
module/parse-package-json.js n=1000000 size='1024-2048'    ***        9.97 %       ±0.84%  ±1.12%  ±1.46%
module/parse-package-json.js n=1000000 size='2048+'        ***        8.83 %       ±0.78%  ±1.04%  ±1.35%

Refs: #55584
Refs: #55591
Refs: #67620

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 19, 2026
@lemire
lemire requested review from anonrig and mcollina November 19, 2026 18:33
`parsePackageJSON()` copies its input into a `std::string` with no
spare capacity. `simdjson::pad()` then appends `SIMDJSON_PADDING`
spaces, so every call reallocated and copied the whole document.
Reserve room for the padding when the input is copied so that the
append happens in place. The padding stays within the string's size,
so simdjson never reads past the end of the string.

Add a benchmark that parses the package.json files under deps/.

Assisted-by: an AI coding agent
Signed-off-by: Daniel Lemire <daniel@lemire.me>
@anonrig anonrig added 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 19, 2026
@lemire
lemire force-pushed the src-reserve-simdjson-padding branch from 9d623d0 to 2e4265a Compare November 19, 2026 18:36
@anonrig anonrig added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Nov 19, 2026
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (42800b6) to head (2e4265a).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
src/node_modules.cc 50.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67623   +/-   ##
=======================================
  Coverage   90.71%   90.72%           
=======================================
  Files         801      801           
  Lines      280923   280925    +2     
  Branches    54240    54243    +3     
=======================================
+ Hits       254839   254856   +17     
+ Misses      16254    16249    -5     
+ Partials     9830     9820   -10     
Files with missing lines Coverage Δ
src/node_modules.cc 79.66% <50.00%> (-0.09%) ⬇️

... and 33 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.

@gurgunday gurgunday 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.

lgtm

@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 20, 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. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants