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

Cache compiled scripts #137

Merged
merged 13 commits into from
Mar 14, 2024
Merged

Cache compiled scripts #137

merged 13 commits into from
Mar 14, 2024

Conversation

brachy84
Copy link
Member

@brachy84 brachy84 commented Mar 6, 2024

This pr allows compiled scripts to be cached between reloads and even restarts. This can speed up subsequent reloads significantly.
The Supersymmetry modpack has an average reload (just groovy not restart) time of 70s. With this pr its only 3 - 7s.

How it works

Groovy compiles scripts into java classes. Before it creates the clas we can obtain the class bytes with a mixin. The class bytes will be immediatly written to a file and out put to cache/groovy/class.name.clz. cache/ is also used by other mods. .clz is not a known file ending afaik. Its just class, but clazz and shorter. The class name, bytes, script path, last modified date and inner class names are saved to a map, which is written to cache/groovy/_index.json.
On restart the index is read. When a script is about to load we can simply check if it exists in the index and define a class with the bytes. When a script is deleted, the cache (and for all inner classes) is automatically deleted.

Additional Information

  • I added a /grs deleteClassCache command wich clears the cache/groovy/ path.
  • I added a version property to the index file. This allows us to automatically delete cache in the future, in case we make changes to loading/saving caches wich are not backwards compatible.
  • It also works with preprocessors. Now they are only parsed when a script is about to be compiled and saved to the index fle.
  • Loaders which are not configured in the run config are no longer being executed.

Copy link
Collaborator

@WaitingIdly WaitingIdly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should preInit scripts be cached? how helpful is caching them?
anyways, ive tested in a few places, and havent gotten any errors related to this change. my comments are just about the part users are going to interact with (the command)

@brachy84 brachy84 added enhancement New feature or request sandbox For internal changes to the sandbox labels Mar 9, 2024
@brachy84 brachy84 merged commit 61cba0b into master Mar 14, 2024
1 check passed
@brachy84 brachy84 deleted the precompiling branch March 14, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sandbox For internal changes to the sandbox
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants