Skip to content

Idea for x5 optimization for functions that return classes, objects or small arrays #997

@munrocket

Description

@munrocket

I noticed that when we create a functions that return Class, Objects or small Array performance become worse than in JS. I was curious why this happens and created a new version of my code and get x7 boost in performance for f64 struct. It can be little bit optimistic because I have too simple structure.

The idea:

When you compile a code it often allocated objects with the same Shapes. It can be a Points, some Tuples or general Objects. All is ok when you create it once or twice in your code, but it can be huge problem when you run this code in loop.

So we can allocate only once a relatively big Turing tape with this objects. And when we invoke a function that return objects with this shapes, we can pass a new index from tape in which we can store result object.

Also we can notice that we can reuse space in this tape for different function scopes. Here a lot of room for your imagination how to do this. For example all methods in one class can have only one temporary cache and another cache for another functions.

Source code:
before, after

Picture with results:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions