Skip to content

cache font outline lookup in path_builder.rs (performance) #3964

@Veercodeprog

Description

@Veercodeprog

node-graph/nodes/text/src/path_builder.rs, immediately before building ReadFontsRef and outline_glyphs() inside PathBuilder::render_glyph_run can be cached for better performance.

Current behavior

For each glyph run, the code:

  • Collects normalized_coords from the run into a Vec.
  • Takes font.data / font.index, constructs ReadFontsRef::from_index(...), and calls outline_glyphs().
  • Iterates glyphs and draws outlines via draw_glyph.

Problem

render_glyph_run can be invoked frequently during text layout and editing. Reconstructing the font reference and outline glyph set for the same underlying font on every call is likely redundant work and may show up in profiling for documents with a lot of text or frequent updates.

Proposed direction

Introduce a cache keyed by something stable for the font instance, such as font data identity plus index, and any other inputs that affect outline access if needed. The cache would store or reuse the equivalent of ReadFontsRef / outline_glyphs() (or another API-appropriate handle) so repeated runs against the same font avoid repeated parsing.

Additional considerations:

  • Optionally reduce allocations, for example by reusing a buffer for normalized_coords, if profiling shows it matters.
  • Ensure thread-safety and lifetime rules match how PathBuilder is used in the text node pipeline.
  • Add a small benchmark or trace comparison before and after, if feasible.

Location

node-graph/nodes/text/src/path_builder.rsPathBuilder::render_glyph_run, near the TODO at around line 102.

Labels

  • performance

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