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

Debulk LED structs #65

Closed
DavJCosby opened this issue Feb 7, 2024 · 0 comments · Fixed by #66
Closed

Debulk LED structs #65

DavJCosby opened this issue Feb 7, 2024 · 0 comments · Fixed by #66
Labels
design Discussing larger design and architecture ideas e/performance Changes intended to improve performance
Milestone

Comments

@DavJCosby
Copy link
Owner

DavJCosby commented Feb 7, 2024

Right now, Leds are represented as follows:

pub struct Led {
    pub color: Rgb,
    position: Vec2,
    direction: Vec2,
    angle: f32,
    distance: f32,
    index: usize,
    segment: usize,
}

Meaning each takes up 56 bytes. At this scale, to represent a setup of 500 leds, 28 kilobytes of memory are required. Combine that with heavy memory footprint of the Sled struct and we run the risk of requiring more memory than some microcontrollers will be able to provide.

Decreasing the size of each LED struct make require more computational work in other places, but will make LEDs more cache friendly and therefore faster to iterate over.

There are a handful of trade-off options but here's what I'm considering:

pub struct Led {
    pub color: Rgb,
    position: Vec2,
    angle: f32,
    distance: f32,
    index: u16,
    segment: u8,
}
  • 32 bytes (43% smaller, 500 leds is ~16kb)
  • index and segment scaled down to smaller types
  • chose angle & distance over a combined offset vector as it lets us precompute two important values at the same size. Also faster to convert from angle to direction than vice versa.

The smaller size for index and segment should have benefits all around. Filters should be smaller (and therefore Drivers), Sled gets a bit less bulky, etc etc.

@DavJCosby DavJCosby added this to the 0.2.0 milestone Feb 7, 2024
@github-project-automation github-project-automation bot moved this to Backlog in 0.2 Roadmap Feb 7, 2024
@DavJCosby DavJCosby added design Discussing larger design and architecture ideas e/performance Changes intended to improve performance labels Feb 7, 2024
@DavJCosby DavJCosby moved this from Backlog to In Progress in 0.2 Roadmap Feb 7, 2024
@DavJCosby DavJCosby linked a pull request Feb 7, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from In Progress to Done in 0.2 Roadmap Feb 8, 2024
@DavJCosby DavJCosby mentioned this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Discussing larger design and architecture ideas e/performance Changes intended to improve performance
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant