Graal Wiki › Guides › Optimize Script Performance and Reduce File Size
Optimize Script Performance and Reduce File Size
Why Graal Mod Keeps File Size Small
Graal Mod bundles a lightweight JavaScript runtime by removing unnecessary files that standard GraalJS includes. This keeps your game installation lean without sacrificing ECMAScript compliance.
Writing Efficient Scripts
To maximize performance, follow these practices:
- Minimize object creation: Reuse variables instead of creating new objects in loops.
- Cache frequently accessed values: Store repeated Java method calls in local variables.
- Use native Java where possible: For heavy computation, call optimized Java methods rather than doing work in JavaScript.
`javascript
// Inefficient
for (let i = 0; i < 1000; i++) {
var obj = new SomeObject();
}
// Better
var obj = new SomeObject();
for (let i = 0; i < 1000; i++) {
obj.reset();
}
`
Monitoring Script Load
Check your game logs for script compilation time. If a script is slow, profile it by timing sections with console.time() and console.timeEnd(). Move bottlenecks to Java if needed. Graal's lightweight design means most performance gains come from smart script design, not the runtime itself.