Skip to content

replace curve in ecpoint with a reference #22

@steven-varga

Description

@steven-varga

Replace curve::C in ECPoint{T,C} with reference to reduce memory usage

Description:

Currently, the ECPoint struct stores a full copy of the curve object:

struct ECPoint{T, C<:Curve}
    point::Point{T}
    curve::C
end

In many cases, especially for static or singleton curves (e.g. base points on a known curve), this results in unnecessary duplication and increased memory pressure. Holding a reference to the curve (or even using a shared singleton via const or Ref) could significantly reduce the memory footprint without impacting correctness.

Proposal:

Refactor ECPoint to hold a reference or shared handle to the curve object. Some ideas:

  • Use const GLOBAL_CURVE = ... and pass reference to that
  • Change curve::Ccurve::Ref{C} or curve::Base.RefValue{C}
  • Use a parametric singleton pattern if curve data is constant

New structure could look like:

struct ECPoint{T, C<:Curve}
    point::Point{T}
    curve::Ref{C}  # or Base.RefValue{C}
end

Tasks:

  • Benchmark construction and point arithmetic with current curve::C
  • Measure memory overhead for large sets of ECPoints
  • Evaluate design options (immutable singleton vs reference container)
  • Implement the chosen strategy
  • Test impact on performance and garbage collection

Motivation:

  • Reduce per-point memory footprint
  • Enable more efficient curve-based cryptographic structures
  • Lay the groundwork for supporting large batches of points over the same curve

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