-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Make GC smarter #17919
base: main
Are you sure you want to change the base?
Make GC smarter #17919
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly style feedback. The overall idea seems good but do you have benchmarks?
@@ -886,7 +887,7 @@ pub const VirtualMachine = struct { | |||
|
|||
module_loader: ModuleLoader = .{}, | |||
|
|||
gc_controller: JSC.GarbageCollectionController = .{}, | |||
gc_controller: *GCController = undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no undefined
defaults
// Check allocation rate (is memory growing rapidly?) | ||
bool rapidMemoryGrowth = m_lastBlockBytesAllocated > 0 && (currentHeapSize > m_lastBlockBytesAllocated * 1.5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How frequently does this run? If it's very frequent then a ratio smaller than 1.5 might make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need floating-point math
return Bun__isBusyDoingImportantWork(bunVM); | ||
} | ||
|
||
bool BunGCController::checkMemoryPressure() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this respond to memory pressure notifications from the system?
Test failures also seem new/relevant |
What does this PR do?
This PR implements a new garbage collection controller, improving coordination between JavaScriptCore's GC and the event loop.
The previous implementation used a timer-based approach that didn't account for application activity and was separate from JSC's timer-based GC mechanism. The new controller is more intelligent, deferring collection while HTTP requests are ongoing. It also detects when 70% or more RSS is in use while a full collection is in progress and attempts to aggressively free more memory.
How did you verify your code works?