Skip to content

Cache flattened headings and anchor map for large markdown files #3

Description

@productengineered

Source

CodeRabbit findings #3 and #5 from PR #2.

What

Two computed properties recompute on every access:

  • flattenedHeadings in ParselyViewModel recursively flattens the heading tree
  • anchorMap in MarkdownDetailView iterates all blocks to build a slug-to-lineIndex lookup

Why deferred

Markdown files in practice have tens of headings, not thousands. The flattening and map-building are O(n) where n is heading count — negligible for real-world files. Premature optimization at this stage adds complexity without measurable benefit.

When to revisit

If Parsely ever supports very large generated markdown files (10K+ lines with hundreds of headings) and profiling shows these as hot paths.

Files

  • app/Parsely/Parsely/ViewModels/ParselyViewModel.swift (lines 90-108)
  • app/Parsely/Parsely/Views/Screens/MarkdownDetailView.swift (lines 7-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions