asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
617 stars 172 forks source link

Integrate 'Coordinated Restore at Checkpoint' #1197

Open abelsromero opened 1 year ago

abelsromero commented 1 year ago

There's an experimental feature to save and restore the state of the JVM that helps to improve startup. Since one of our main pain points is the initial parsing of the gem which takes most of the time when converting a single document, this could be a great improvement.

References:

I know that I am not the first to think about it /cc @someth2say

someth2say commented 1 year ago

Yes! In my current daywork we are already using AppCDS, that is a "lightweight" version of CRaC. AppCDS stores the statically initialized classes when the application shuts down, so it shaves a few seconds from initializing JRuby. But, AFAIK, AppCDS does not store information about the dinamically generated classes, so the benefit is limited.

CRaC works a bit differently: It stores the whole status of the JVM. So CRaC will definitelly boost the startup. But with CRaC, it is the developer who decides when and where (file) to create the checkpoint.

So this arises two questions in my mind: 1) Can AsciidoctorJ decide when to create the checkpoint. I don´t think so, as that is a stop-the-world action. If we want to go this way, we probably need to add an extension API for devs to be able to decide the moment. 2) Where do we create the checkpoint (in the FS)? I am not sure if we are already using some kind of starndard place to save things (maybe XDG Base Directory Specification?), but in any case I feel messing with host FS a bit off.

abelsromero commented 1 year ago

So this arises two questions in my mind:

This is a research story more than anything 💡 My first idea was creating a snapshot around RubyGemsPreloader::preloadRequiredLibraries which parses the gems and we know it's the main culprit of slow startup and see if it improves anything. Then, if it works, we could bundle any extra file in the jar and load it from the classpath. We'd need to upgrade the snapshot on every asciidoctor Ruby gem upgrade only.

abelsromero commented 9 months ago

Another article on the topic for reference https://openliberty.io/blog/2023/09/26/spring-boot-3-instant-on.html

someth2say commented 9 months ago

Nice one. Sadly, it seems that only a few Java implementations support CrAC: OpenLiberty, Eclipse and Zulu. OpenJDK has also a variant that supports CrAC, but not in the main stream.

abelsromero commented 9 months ago

Another article on the topic https://spring.io/blog/2023/10/16/runtime-efficiency-with-spring. Nothing relevant though, only interesting to see that it's being adopted, even if in early builds.