Skip to content

Typst paper compile: finish optimization pass and verify output #1037

@isPANN

Description

@isPANN

Context

Profiling make paper showed docs/paper/reductions.typ took ~27 s to compile. Two hot spots:

  1. load-example / load-model-example doing O(n²) linear scans over data/examples.json (228 rules + 193 models, 279 call sites).
  2. find-edge / get-reductions-to / get-reductions-from / render-complexity re-scanning reduction_graph.json edges and resolving nodes.at(e.source).name on every call.

Done so far

  • Pre-indexed example-db into _rules-index / _models-index dicts keyed by "src->tgt" / problem name. Bucketed lookup + small filter on variant (docs/paper/reductions.typ:17-72).
  • Pre-indexed graph-data: _graph-edges-resolved (source/target name resolved once), _edges-by-source-name, _edges-by-target-name, _edge-by-pair, _nodes-by-name. Rewrote find-edge, get-reductions-to/from, render-complexity to use them.

Result: 27 s → ~9.7 s (≈2.8×).

Remaining work

  1. Verify PDF output is identical. Compare old vs new reductions.pdf — check page count, figure placement, example renderings, completeness warnings. No semantic regressions.
  2. Shrink examples.json (currently 19 MB). rule.solutions[].target_config is 91 % of the file; 26 MB of that comes from a single rule (tracked in KSatisfiability → TimetableDesign reduction: gadget blowup 64·L² seems excessive #1036). Once KSatisfiability → TimetableDesign reduction: gadget blowup 64·L² seems excessive #1036 lands, regenerate the fixture and re-measure.
  3. Optional fallback if KSatisfiability → TimetableDesign reduction: gadget blowup 64·L² seems excessive #1036 is slow to land: sparse-encode target_config as target_config_ones: [indices] in the export script, update ~12 call sites in reductions.typ. Expected: 19 MB → ~1.5 MB, compile ~3–4 s.
  4. Commit the optimization. Currently the changes live only in a dirty working copy on main.

Files touched

  • docs/paper/reductions.typ (indexing helpers + rewritten lookup functions)

Definition of done

  • make paper compiles in ≤ 5 s on a warm cache.
  • reductions.pdf visually matches the pre-optimization version (spot check + page count).
  • No new Typst warnings.
  • Optimization committed to main with a short commit message explaining the indexing pattern.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions