Skip to content

feat: Add global bytecode cache for Eluna scripts #293

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

iThorgrim
Copy link

@iThorgrim iThorgrim commented Aug 19, 2025

Summary

Implements an in-memory bytecode cache and adds support for pre-compiled .out files, significantly improving script reload performance by avoiding recompilation of unchanged files.

Key Features

  • Global cache that survives .reload eluna commands
  • Smart invalidation based on file modification timestamps
  • Support for all script types: .lua, .ext, .moon, and .out files
  • Configurable via Eluna.BytecodeCache setting (default: enabled)

Changes

  • Added support for loading pre-compiled .out files (generated by luac)
  • Added GlobalCacheEntry structure for cache storage
  • Implemented TryLoadFromGlobalCache() with single-lock validation
  • Created unified LoadScriptWithCache() for all script types
  • Added timestamp cache to minimize filesystem calls

Backward Compatibility

  • Fully backward compatible - no breaking changes
  • Default enabled for immediate performance benefits
  • Fallback mechanisms ensure scripts load even if cache fails

Example Logs

With ByteCode Cache before reload:

[Eluna]: Searching scripts from `lua_scripts`
[Eluna]: Executed 5 Lua scripts in 0 ms (4 compiled, 0 cached, 1 pre-compiled)

With ByteCode Cache after reload:

[Eluna]: Searching scripts from `lua_scripts`
[Eluna]: Executed 5 Lua scripts in 0 ms (0 compiled, 4 cached, 1 pre-compiled)

Without ByteCode Cache:

[Eluna]: Searching scripts from `lua_scripts`
[Eluna]: Executed 5 Lua scripts in 0 ms

Testing

Verified with mixed .lua, .moon, and .out files.

@iThorgrim iThorgrim added the enhancement New feature or request label Aug 19, 2025
@TheSCREWEDSoftware
Copy link

I would suggest the config file just have "Cache" or "Script Cache" instead of complex name that the user may not understand what is, even with the description with.

@iThorgrim
Copy link
Author

I would suggest the config file just have "Cache" or "Script Cache" instead of complex name that the user may not understand what is, even with the description with.

I understand the concern, but "Bytecode Cache" is a deliberate choice:

  • The option doesn’t cache raw scripts, but their compiled bytecode.
  • Calling it just "Script Cache" would be misleading, since it could suggest file or runtime caching.
  • The current name matches the actual mechanism, and the description in the config explains it clearly enough for non-technical users.

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

Successfully merging this pull request may close these issues.

2 participants