Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions cli/lib/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,36 @@

pub async fn execute_main_module(&mut self) -> Result<(), CoreError> {
let id = self.worker.preload_main_module(&self.main_module).await?;
self.worker.evaluate_module(id).await
self.worker.evaluate_module(id).await?;

// After loading and evaluating all modules, trim the glibc malloc arena.
// Module loading/TypeScript compilation creates heavy allocation churn
// that glibc's allocator doesn't release back to the OS, causing RSS on
// Linux to be much higher than on other platforms (see #25722).
#[cfg(target_os = "linux")]
{
// SAFETY: calling libc malloc_trim which is safe to call at any time.
unsafe {
libc::malloc_trim(0);

Check failure on line 868 in cli/lib/worker.rs

View workflow job for this annotation

GitHub Actions / lint debug linux-x86_64

failed to resolve: use of unresolved module or unlinked crate `libc`
}
}

Ok(())
}

pub async fn execute_side_module(&mut self) -> Result<(), CoreError> {
let id = self.worker.preload_side_module(&self.main_module).await?;
self.worker.evaluate_module(id).await
self.worker.evaluate_module(id).await?;

#[cfg(target_os = "linux")]
{
// SAFETY: calling libc malloc_trim which is safe to call at any time.
unsafe {
libc::malloc_trim(0);

Check failure on line 883 in cli/lib/worker.rs

View workflow job for this annotation

GitHub Actions / lint debug linux-x86_64

failed to resolve: use of unresolved module or unlinked crate `libc`
}
}

Ok(())
}

pub async fn execute_preload_modules(&mut self) -> Result<(), CoreError> {
Expand Down
Loading