Skip to content

typing/perf 1/4: counters, phase profiler, scaling bench harness - #80

Open
Felipe705x wants to merge 1 commit into
mainfrom
tc-perf/01-instrumentation
Open

typing/perf 1/4: counters, phase profiler, scaling bench harness#80
Felipe705x wants to merge 1 commit into
mainfrom
tc-perf/01-instrumentation

Conversation

@Felipe705x

Copy link
Copy Markdown
Collaborator

First of a stacked series optimizing the static typechecker. This PR adds measurement only — no behavior change.

  • src/typing/stats.rs: always-on thread-local counters for the checker's hot primitives (refine calls + schema entries scanned, env meet/union/outer-join/to-group, PathType meets).
  • Typechecker::enable_profiling(): opt-in per-phase wall split of check_query (one branch per phase when off).
  • pattern_typecheck: generated scaling families (chain_N, chain_dir_N, anydir_N, union_W, anon_unlabeled_N, repeats, subqueries), --star-schema control, per-case counter + phase CSV columns, batch timing for sub-2 µs cases, per-case iteration budget.

Baseline captured (LDBC SF0.1 schema, 11 node / 25 edge entries):

  • Labeled chains scale linearly, ~28 µs/hop (~23 µs of that is schema scanning per the star-schema control).
  • Pathological find that drives the rest of the series: unlabeled chains blow up exponentially in structure size with linear call counts()-[]->() ×16 measured 23.3 s per check_query (N=8: 32 ms). Cause analysis in PR 4/4.

Merge gate: none beyond review — measurement-only.

🤖 Generated with Claude Code

Instrumentation pass before optimizing the typechecker (measure first):

- src/typing/stats.rs: thread-local always-on counters for the hot
  primitives (refine calls + schema entries scanned per arm,
  refine_to_nodes, env meet/union/outer_join/to_group, PathType::meet).
  reset()/snapshot() around a region; increments are noise next to the
  schema scans they count.
- Typechecker::enable_profiling(): per-phase wall split of check_query
  (pattern / rep-checks / group_by / returns / order_by) behind an
  Option<Box<PhaseProfile>> that costs one branch per phase when off.
- pattern_typecheck: adds generated scaling families against the LDBC
  schema (chain_N, chain_dir_N, anydir_N, union_W, repeat_bounded,
  subq, anon_unlabeled_N), a --star-schema small-schema control,
  per-case counter + phase columns in the CSV, batch timing for
  sub-2us cases, and a per-case iteration budget so pathological
  cases cannot stall the run.

Baseline (LDBC SF0.1 schema, 11 node / 25 edge entries, warm):
- labeled chains scale linearly: ~28 us/hop (chain_16 = 448 us), of
  which ~23 us/hop is schema scanning (star-schema control: 5 us/hop).
- refine dominates labeled patterns: chain_16 = 65 refine calls /
  400 edge entries scanned.
- pathological find: unlabeled chains blow up exponentially in
  structure SIZE with linear call counts (anon_unlabeled_8 = 32 ms,
  anon_unlabeled_16 = 23.3 s per check_query) -- PathType carries the
  full prefix history per union arm, so width multiplies per hop by
  the compatible-schema-entry count.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant