Skip to content

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

Closed

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:

Activity

  1. MaxGraey commented on Dec 7, 2019

    @MaxGraey
    Member

    Object explosion optimization aka scalar replacement (when simple objects represent as set of variables/registers without alloc in memory) is not yet present. Also that could be easily handle / optimize when multi-values will landed.

    Btw you could improve speed even more by using global variables instead array. Replace this

    let R = new Float64Array(16)

    to

    let R0 = 0.0;
    let R1 = 0.0;
    ...
    let R15 = 0.0;
  2. MaxGraey commented on Dec 7, 2019

    @MaxGraey
    Member

    Also I'm not sure you need so many variables. I guess one or two will be enough

  3. munrocket commented on Dec 9, 2019

    @munrocket
    Author

    Yep, you right with one variable optimization even better. Huge impact.

  4. changed the title [-]Idea for x3 optimization for functions that return classes, objects or small arrays[/-] [+]Idea for x5 optimization for functions that return classes, objects or small arrays[/+] on Dec 9, 2019
  5. munrocket commented on Dec 14, 2019

    @munrocket
    Author

    This will be not acutal after Platform-independent Just-in-Time (JIT) compilation. But we don't know when it will be implemented.

  6. stale commented on Jan 26, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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