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

Heap snapshot support #35

Closed
juancampa opened this issue Jul 14, 2019 · 4 comments
Closed

Heap snapshot support #35

juancampa opened this issue Jul 14, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@juancampa
Copy link

juancampa commented Jul 14, 2019

I'm looking for a JS engine with the ability to take snapshots of the JS heap at an arbitrary points in time. The idea is for snapshots to be serialized, saved to disk, and later deserialized in a completely different process to continue execution. V8 can do this with its SnapshotCreator but it can be a rather slow process.

I scanned through the code but didn't find anything. I was wondering if:

  1. Is this by any chance in your roadmap?
  2. Could this be implemented with the current architecture in a practical/elegant/performant way?
@dulinriley
Copy link
Contributor

It is on our roadmap, @avp can say more

@dulinriley dulinriley added the enhancement New feature or request label Jul 15, 2019
@dulinriley
Copy link
Contributor

Sorry that we haven't gotten back to this issue in a while, but unfortunately we took it off our roadmap.

I'll summarize the main issues that we've faced trying to implement this:
The ideal serialized format of the heap would be something you could mmap in as writable pages, then reconstruct the stack and continue forward. The main issue to doing this is pointers, because addresses might not be the same when you resume. For JS pointers, we had this covered by compressing them into a heap segment number + offset (encoded as 32 bits, thus compressing a 64 bit pointer). The issue mostly had to do with native pointers to complicated off-heap structures.

So, failing to find a solution that allowed an mmap, we tried defining a serialization format for each object, and pointers to off-heap structures were copied into a separate portion of the file, and a fake pointer was inserted that would need a fixup pass. This mechanism required allocating all the memory piece-by-piece into the GC again, and this turned out to be too slow, for most test cases it was about the same as running the original JS from the beginning.

Another big blocker is what to do with HostObjects and HostFunctions. These are critical to React Native and are used very early in Hermes's startup path. We would have to provide a custom serializer, and these HostObjects might point to things like Java resources, or files, or various other things that would be very hard to deserialize, and might not even be usable when they were deserialized (like a short-lived URL, for example).

We haven't found anything that definitively solves these problems, so we took it off our roadmap.
If someone in the community knows a creative solution to some of these issues, we welcome suggestions or PRs showing how it could be done.

@tmikov
Copy link
Contributor

tmikov commented Oct 15, 2020

For the record, we do have heap serialization, but we don't actively support it.

@rimmer
Copy link

rimmer commented Aug 10, 2021

For the record, we do have heap serialization, but we don't actively support it.

I know, that this is not a support forum, but Hermes does not have any so, I would appreciate if you could give some hints where to look for :)

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants