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

bug: much area() induces lag even if transform is never changed #538

Open
dragoncoder047 opened this issue Nov 24, 2024 · 5 comments
Open
Assignees
Labels
bug Something isn't working performance Something that will make the project faster

Comments

@dragoncoder047
Copy link
Contributor

dragoncoder047 commented Nov 24, 2024

kaplay({
    tagsAsComponents: true,
});

loadBean();

function recur(obj, level) {
    if (level < 0) return;
    const obj2 = obj.add([
        pos(rand(vec2(0), vec2(100))),
        scale(rand(vec2(2))),
        rotate(rand(0, 360)),
    ]);
    if (level === 0) {
        obj2.use(sprite("bean"));
        // obj2.use(area());
    }
    recur(obj2, level - 1);
}

for (var i = 0; i < 500; i++)
    recur(getTreeRoot(), 2);
var frames = 0;
onUpdate(() => {
    frames++;
    debug.log((frames / time()).toFixed());
});

This creates 500 objects with random transforms, with 3 objects nested in each, and on the lowest level, it just adds area(). (commented out above cause less laggy). The transforms are not changing, yet if area() is used it lags much.

Results from kaplyground

Browser FPS w/o area() FPS with area()
Chrome 131 120 2 (but it claims 6)
Firefox 132 119 1 (but it claims 5)
Safari 18.1.1 20 0.5 (but it claims 4)
@dragoncoder047 dragoncoder047 added the bug Something isn't working label Nov 24, 2024
@dragoncoder047
Copy link
Contributor Author

dragoncoder047 commented Nov 24, 2024

The strange thing is that this only occurs in the kaplayground, I can't reproduce it when I copy it into a local example in my fork of kaplay, they all get max fps. Even the "export to html" opened via a file:// URL gets lag, but the localhost:8000 version from vs code does not lag.

@dragoncoder047
Copy link
Contributor Author

I can't reproduce it when I copy it into a local example in my fork of kaplay

Turns out this is because the "new tag methods" broke something , if you change tagsAsComponents: true it lags like expected

@mflerackers
Copy link
Member

transforms and areas are going to be cached in the future, so at least they won't be recalculated each frame

@dragoncoder047
Copy link
Contributor Author

ah good, my game am getting like 5 FPS in Chrome which is the best...

do you have an eta on the caching?

@mflerackers
Copy link
Member

mflerackers commented Nov 24, 2024 via email

@lajbel lajbel added this to KAPLAY.js Nov 28, 2024
@lajbel lajbel moved this to WIP in KAPLAY.js Nov 28, 2024
@lajbel lajbel changed the title REALLY IMPORTANT BUG: much area() induces lag even if transform is never changed bug: much area() induces lag even if transform is never changed Nov 28, 2024
@lajbel lajbel added the performance Something that will make the project faster label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Something that will make the project faster
Projects
Status: WIP
Development

No branches or pull requests

3 participants