Avoid storing Module/SemContext in non-debug global eval#2090
Merged
Conversation
Summary: Pull Request resolved: facebook#2053 `BCProviderFromSrc` is typically used in debug and dev scenarios, but some users also invoke it via production global `eval`. We don't want to keep the `M` and `semCtx` alive for these cases, because the debugger doesn't exist and there's no lazy compilation to require this data. It just bloats memory usage and is never accessed. Note that this won't reduce memory usage for large `eval` strings when smart compilation is enabled, because that still uses lazy compilation. To fix it in those scenarios, the user must also pass `CompilationMode::ForceEagerCompilation` to `RuntimeConfig`. Ran a simple `eval` benchmark: ``` (function() { globalThis.arr = []; var N = 10_000; for (var i = 0; i < N; ++i) { var f = (1,eval)(` function foo_${i}() {} `); globalThis.arr.push(f); } // loop while we check the memory gc(); for (;;) {} })(); ``` This diff takes the total memory usage from 950 MB to 140 MB (measured with Activity Monitor on M4 Max MacBook). Reviewed By: lavenzg Differential Revision: D108782017 fbshipit-source-id: 526f1ab1e3c4347d312270f11c6ba3ca5813fb4a
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.
Summary:
Pull Request resolved: #2053
BCProviderFromSrcis typically used in debug and dev scenarios, but some users also invoke it via production globaleval.We don't want to keep the
MandsemCtxalive for these cases, because the debugger doesn't exist and there's no lazy compilation to require this data. It just bloats memory usage and is never accessed.Note that this won't reduce memory usage for large
evalstrings when smart compilation is enabled, because that still uses lazy compilation. To fix it in those scenarios, the user must also passCompilationMode::ForceEagerCompilationtoRuntimeConfig.Ran a simple
evalbenchmark:This diff takes the total memory usage from 950 MB to 140 MB (measured with Activity Monitor on M4 Max MacBook).
Reviewed By: lavenzg
Differential Revision: D108782017
fbshipit-source-id: 526f1ab1e3c4347d312270f11c6ba3ca5813fb4a