Skip to content

Optimize Semantic's structs-of-arrays and make API simpler #11

@overlookmotel

Description

@overlookmotel

Problem

Semantic uses a struct of arrays pattern for ScopeTree and other structures.

If we do oxc-project/oxc#4269, then ScopeTree would be purely a collection of IndexVecs. Then we can optimize it.

At present we treat all 6 x IndexVecs as independent. When creating a scope, we push to each vec independently.

This is inefficient in 3 ways:

  1. len and capacity are stored 6 times. They only need to be stored once, as they're the same for all 6 vecs.
  2. Each time we add a scope, IndexVec::push looks up len for that vec, checks if it's at capacity, and grows if required. These lookups/checks happen 6 times, when they only need to happen once.
  3. Looking up multiple pieces of information about a scope will involve multiple bounds checks, when only 1 is required.

Potential solution

Find a crate which optimizes SOA structures to avoid these penalties. Hopefully one exists, but if not, create one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions