Skip to content

cache#17

Open
HEIHUAa wants to merge 1 commit intoCodenameCrew:codename-devfrom
HEIHUAa:cache
Open

cache#17
HEIHUAa wants to merge 1 commit intoCodenameCrew:codename-devfrom
HEIHUAa:cache

Conversation

@HEIHUAa
Copy link
Copy Markdown

@HEIHUAa HEIHUAa commented Mar 29, 2026

It implements a variable location caching system that stores where each variable is found (global, customClass, scriptObject, etc.) to speed up repeated lookups during script execution.

Add variable caching to improve performance in most scenarios.

var i = 0;
while(i < $iterationsPerFrame) {
    var songPos = Conductor.songPosition;
    note.x = note.x + songPos * 0.0001;
    note.y = note.y + FlxG.elapsed;
    i = i + 1;
}
note.x + note.y;

↑This code, which runs multiple times per frame, saw a 1.33x speedup in testing.

var songPos = Conductor.songPosition;
var crochet = Conductor.crochet;
var bpm = Conductor.bpm;

var diff = songPos - note.strumTime;
var progress = diff / crochet;

note.x = 100 + progress * 50;
note.y = 200 + Math.sin(songPos * 0.01) * 20;
note.alpha = 1 - progress * 0.5;
note.angle = progress * 360;
note.scale.x = 1 + progress * 0.2;
note.scale.y = 1 + progress * 0.2;

note.x + note.y;

↑This complex per-frame script saw a 1.05x speedup.

var songPos = songPosition;
var c = crochet;
var b = bpm;
songPos + c + b;

↑Per-frame script execution on scriptObject saw a 2x speedup!

var localX = 0;
var localY = 0;
var i = 0;
while(i < $iterationsPerFrame) {
    localX = localX + Conductor.songPosition * 0.001;
    localY = localY + FlxG.elapsed;
    if(localX > 100) localX = 0;
    if(localY > 100) localY = 0;
    i = i + 1;
}
localX + localY;

↑This code using local variables showed no performance improvement.

In short, for scripts with almost no repeated calls, this could potentially reduce performance, but such scenarios are practically non-existent in real-world use. And even if they do occur, they wouldn't become the primary performance bottleneck.

Based on my testing, I haven't found any runtime issues — at least, I've run several large mods without encountering any problems.

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.

1 participant