Skip to content

Make js modules cacheable when invoking functions - #33

Merged
andreaTP merged 3 commits into
roastedroot:mainfrom
andreaTP:cacheable-js-module
Jun 16, 2025
Merged

andreaTP merged 3 commits into
roastedroot:mainfrom
andreaTP:cacheable-js-module

Conversation

@andreaTP

@andreaTP andreaTP commented Jun 12, 2025 •

Copy link
Copy Markdown
Collaborator

This is a proof of concept to make possible compiling a static JS payload and dynamically invoke functions in it.

The design is:

  • we generate a module that expects a specific json payload on stdin on start
  • the specific json on stdin is designed to invoke a function and return the result to the host
  • there is a bit of ser/deser magic involved

Early results suggest this is the way forward as there is a 10X speed improvement during execution.

// protocol
// { moduleName: "..", functionName: "..", args: "stringified args" }
private String jsReadStdIn() {
return "function readInput() {\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I didn't look to see what version of Java you are targeting. But you might use a multi-line string here instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We keep compatibility with Java 11... I'd probably offload to external js files.

FWIW the code is directly copy pasted from here.

@andreaTP andreaTP changed the title [WIP] Make js modules cacheable when invoking functions Make js modules cacheable when invoking functions Jun 16, 2025
@andreaTP

Copy link
Copy Markdown
Collaborator Author

Changed the design and it feels better now, the caching mechanism is super low level, but should work in 90%+ of the cases.
In case we want to avoid additional reads and writes to memory we can probably optimize further down the line.

@andreaTP
andreaTP marked this pull request as ready for review June 16, 2025 14:47
@andreaTP
andreaTP merged commit 5877119 into roastedroot:main Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants