emilk / emilk/egui_plot

Rethink data organization

Open
#222 6 comments 0 reactions 0 assignees View on GitHub
good challenging issue planning
Dominant language
Rust
Stars
468
Forks
108
Avg merge
15m
Merged PRs (30d)
3

Description

Currently you need to pass `PlotPoints` resp. `Vec` as inputs for plotting. This is called AoS (array-of-structures). AoS is in my humble opinion not as good as SoA.

# Reasoning

AoS is inefficient:

1. A common use-case for plotting is time-series plots, with shared x-axis. The AoS forces you to make a copy of xs for each line plot, ~doubling memory requirements.
2. It does not allow to slice data efficiently, i.e. to manage ranges of data given current plot bounds.
3. Poorer cache locality for typical access patterns (e.g. compute min/max for plot bounds)
4. It is hard to extend. Some plot items may require more data (i.e. recently colormap) which forces every user of PlotPoint to pass even more data, which may not be used at all, and breaks public API every time.

Better alternative in terms of performance is generally SoA (structure-of-arrays):

5. SoA better aligns with SIMD / most graphics APIs and shaders prefer SoA-like layouts.
6. Addresses weakness points of AoS.

Disadvantages of SoA:

7. xs and ys must have the same length, but this is no longer enforced by the type system - requires runtime checks or truncation.
8. Passing two slices is more verbose than a single Vec.

# Proposal

Proposal is to get rid of `Vec` and instead pass `xs: &[f32]` and `ys: &[f32])`.
This would be a major breaking change.

# Related PRs/issues

#76

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.