Skip to content

Reduce memory usage of allocation profiles - #188

Merged
szegedi merged 2 commits into
mainfrom
szegedi/cheaper-heap-profile
Jan 15, 2025
Merged

Reduce memory usage of allocation profiles#188
szegedi merged 2 commits into
mainfrom
szegedi/cheaper-heap-profile

Conversation

@szegedi

@szegediszegedi commented Jan 15, 2025

Copy link
Copy Markdown

When the profiler hands off the collected V8 profiles to the rest of the processing code written in TypeScript, it transforms the V8 profile tree into a tree of JS objects. They all have the same string-valued keys. For time (wall and CPU) profiles, we have a mechanism to only create the key string values once per serialization and use them in every node object. For allocation profiles, we didn’t have this logic before, this PR implements it.

That’s 63 characters/node object less for keys name, scriptName, scriptId, lineNumber, columnNumber, children, and allocations and 14 characters/allocation object less for keys sizeBytes and count, plus extra overhead for the string value itself.

This tree only exists for a short period of time (once every 65 seconds between V8 capturing the allocation profile to us transforming it into pprof format) but its footprint still contributes to the peak memory use of the profiler.

Customers are sometimes running Node.js in constrained container environments, so reducing the peak memory use of the profiler is a worthwhile goal.

This currently handles periodic and on-shutdown profiles, but does not handle the special case (with a separate path) of allocation profile capture at OOM using kInterruptCallback mode but it would be easy to extend it for that as well.

JIRA: PROF-11123

@github-actions

github-actionsBot commented Jan 15, 2025

Copy link
Copy Markdown

Overall package size

Self size: 9.52 MB
Deduped: 9.9 MB
No deduping: 9.9 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | source-map | 0.7.4 | 226 kB | 226 kB | | pprof-format | 2.1.0 | 111.69 kB | 111.69 kB | | p-limit | 3.1.0 | 7.75 kB | 13.78 kB | | delay | 5.0.0 | 11.17 kB | 11.17 kB | | node-gyp-build | 3.9.0 | 8.81 kB | 8.81 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@szegediszegedi added the semver-patch Bug or security fixes, mainly label Jan 15, 2025
@pr-commenter

pr-commenterBot commented Jan 15, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-01-15 14:41:46

Comparing candidate commit 6ce12d0 in PR branch szegedi/cheaper-heap-profile with baseline commit 784f6f6 in branch main.

Found 1 performance improvements and 1 performance regressions! Performance is the same for 94 metrics, 24 unstable metrics.

scenario:profiler-idle-with-wall-profiler-18

  • 🟩 cpu_user_time [-7.795ms; -2.211ms] or [-10.739%; -3.046%]

scenario:profiler-light-load-with-wall-profiler-22

  • 🟥 cpu_user_time [+4.384ms; +10.687ms] or [+4.170%; +10.164%]

@szegedi
szegediforce-pushed the szegedi/cheaper-heap-profile branch from b746045 to 484159bCompareJanuary 15, 2025 13:51
Comment threadbindings/profile-translator.hh Outdated
v8::Local<v8::Array> emptyArray = v8::Array::New(isolate, 0);

protected:
inline v8::Local<v8::Object> NewObject() { return v8::Object::New(isolate); }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Methods defined inside class are already implicitly inlined:

Suggested change
inlinev8::Local<v8::Object> NewObject() { returnv8::Object::New(isolate); }
v8::Local<v8::Object> NewObject() { returnv8::Object::New(isolate); }

Comment threadbindings/profile-translator.hh Outdated
return obj->Set(context, key, value);
}

inline explicit ProfileTranslator() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
inlineexplicitProfileTranslator() {}
ProfileTranslator() = default;

nsavoire
nsavoire previously approved these changes Jan 15, 2025
@szegedi
szegedi merged commit 14b2d4f into mainJan 15, 2025
@szegedi
szegedi deleted the szegedi/cheaper-heap-profile branch January 15, 2025 15:16
szegedi added a commit that referenced this pull request Jan 22, 2025
@szegediszegedi mentioned this pull request Jan 22, 2025
Merged
szegedi added a commit that referenced this pull request Jan 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-patchBug or security fixes, mainly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@szegedi@nsavoire