Skip to content
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

feat(runtime,serverless): add V8 heap snapshots #591

Merged
merged 5 commits into from
Feb 17, 2023
Merged

Conversation

QuiiBz
Copy link
Member

@QuiiBz QuiiBz commented Feb 17, 2023

Add a build.rs in crates/serverless to generate a snapshot.bin file containing a V8 heap snapshot of the js-runtime code, which is then used when booting isolates (which only contains the user's code). It's not mandatory to use a snapshot to start a Lagon runtime, but it currently reduces the cold start by a lot. Here's a before/after running 6 times a cold start:

Before (or by not providing a V8 snapshot):

Statistics: IsolateStatistics { cpu_time: 5.660791ms, memory_usage: 583232 }
Statistics: IsolateStatistics { cpu_time: 3.700791ms, memory_usage: 583232 }
Statistics: IsolateStatistics { cpu_time: 3.214416ms, memory_usage: 583232 }
Statistics: IsolateStatistics { cpu_time: 2.923625ms, memory_usage: 583232 }
Statistics: IsolateStatistics { cpu_time: 3.115166ms, memory_usage: 583232 }
Statistics: IsolateStatistics { cpu_time: 3.400375ms, memory_usage: 583232 }

After, providing a V8 snapshot:

Statistics: IsolateStatistics { cpu_time: 3.1ms, memory_usage: 621864 }
Statistics: IsolateStatistics { cpu_time: 902.291µs, memory_usage: 621864 }
Statistics: IsolateStatistics { cpu_time: 651.5µs, memory_usage: 621864 }
Statistics: IsolateStatistics { cpu_time: 853.208µs, memory_usage: 621864 }
Statistics: IsolateStatistics { cpu_time: 584.375µs, memory_usage: 621864 }
Statistics: IsolateStatistics { cpu_time: 842.125µs, memory_usage: 621864 }

The first cold start goes from ~5ms to ~3ms, and subsequent cold starts goes from ~3ms to ~800us.

About

Following #255:

  • Run the tests with and without the heap snapshot, using the ignore-snapshot feature
  • Split sync and async bindings to globalThis.LagonSync and globalThis.LagonAsync, because async bindings can't be serialized - only sync bindings are

@vercel
Copy link

vercel bot commented Feb 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 17, 2023 at 6:31PM (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 17, 2023 at 6:31PM (UTC)
storybook ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 17, 2023 at 6:31PM (UTC)
www ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 17, 2023 at 6:31PM (UTC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant