-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: add percentage support to --max-old-space-size #59082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c837d14
90f8288
84d3433
ebaa850
c377756
a23ece3
b919043
8e5f5ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,25 +109,23 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors, | |
| } | ||
|
|
||
| void PerIsolateOptions::HandleMaxOldSpaceSizePercentage( | ||
| std::vector<std::string>* errors, std::string* max_old_space_size) { | ||
| std::string original_input_for_error = *max_old_space_size; | ||
|
|
||
| // Remove the '%' suffix | ||
| max_old_space_size->pop_back(); | ||
|
|
||
| // Check if the percentage value is empty after removing '%' | ||
| if (max_old_space_size->empty()) { | ||
| errors->push_back("--max-old-space-size percentage must not be empty"); | ||
| std::vector<std::string>* errors, | ||
| std::string* max_old_space_size_percentage) { | ||
| std::string original_input_for_error = *max_old_space_size_percentage; | ||
| // Check if the percentage value is empty | ||
| if (max_old_space_size_percentage->empty()) { | ||
| errors->push_back("--max-old-space-size-percentage must not be empty"); | ||
| return; | ||
| } | ||
|
|
||
| // Parse the percentage value | ||
| char* end_ptr; | ||
| double percentage = std::strtod(max_old_space_size->c_str(), &end_ptr); | ||
| double percentage = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why double? It's likely best to just allow integer values here between 0 and 100. Not critical, of course, I'd just find it a bit cleaner
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should this be an integer, or would a float provide better flexibility for nodes with a large amount of memory?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really depends on how granular we want it to be. Personally I'd be fine with integer and just not worry about fractional percentages but I'd be interested in what others think
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it was a breaking change I would agree, but this is a new feature, why not support more usecases even if they are rare? |
||
| std::strtod(max_old_space_size_percentage->c_str(), &end_ptr); | ||
|
|
||
| // Validate the percentage value | ||
| if (*end_ptr != '\0' || percentage <= 0.0 || percentage > 100.0) { | ||
| errors->push_back("--max-old-space-size percentage must be greater " | ||
| errors->push_back("--max-old-space-size-percentage must be greater " | ||
| "than 0 and up to 100. Got: " + original_input_for_error); | ||
| return; | ||
| } | ||
|
|
@@ -145,13 +143,13 @@ void PerIsolateOptions::HandleMaxOldSpaceSizePercentage( | |
| size_t calculated_mb = static_cast<size_t>(memory_mb * percentage / 100.0); | ||
|
|
||
| // Convert back to string | ||
| *max_old_space_size = std::to_string(calculated_mb); | ||
| max_old_space_size = std::to_string(calculated_mb); | ||
| } | ||
|
|
||
| void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors, | ||
| std::vector<std::string>* argv) { | ||
| if (!max_old_space_size.empty() && max_old_space_size.back() == '%') { | ||
| HandleMaxOldSpaceSizePercentage(errors, &max_old_space_size); | ||
| if (!max_old_space_size_percentage.empty()) { | ||
| HandleMaxOldSpaceSizePercentage(errors, &max_old_space_size_percentage); | ||
| } | ||
|
|
||
| per_env->CheckOptions(errors, argv); | ||
|
|
@@ -1124,10 +1122,12 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( | |
| "help system profilers to translate JavaScript interpreted frames", | ||
| V8Option{}, | ||
| kAllowedInEnvvar); | ||
| AddOption("--max-old-space-size", | ||
| "set V8's max old space size. SIZE is in Megabytes (e.g., '2048') " | ||
| "or as a percentage of available memory (e.g., '50%').", | ||
| &PerIsolateOptions::max_old_space_size, kAllowedInEnvvar); | ||
| AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvvar); | ||
| AddOption("--max-old-space-size-percentage", | ||
| "set V8's max old space size as a percentage of available memory " | ||
| "(e.g., '50%'). Takes precedence over --max-old-space-size.", | ||
| &PerIsolateOptions::max_old_space_size_percentage, | ||
| kAllowedInEnvvar); | ||
| AddOption("--max-semi-space-size", "", V8Option{}, kAllowedInEnvvar); | ||
| AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvvar); | ||
| AddOption( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.