Skip to content

Rethink data organization #222

@michalsustr

Description

@michalsustr

Currently you need to pass PlotPoints resp. Vec<PlotPoint { x, y }> 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):

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

Disadvantages of SoA:

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

Proposal

Proposal is to get rid of Vec<PlotPoint { x, y }> and instead pass xs: &[f32] and ys: &[f32]).
This would be a major breaking change.

Related PRs/issues

#76

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions