Skip to content

Reduce latency with vector-based formula - #283

Open
matthieugomez wants to merge 8 commits into
FixedEffects:mainfrom
matthieugomez:vector-terms
Open

Reduce latency with vector-based formula#283
matthieugomez wants to merge 8 commits into
FixedEffects:mainfrom
matthieugomez:vector-terms

Conversation

@matthieugomez

@matthieugomez matthieugomez commented Aug 28, 2026

Copy link
Copy Markdown
Member

Rewrites the formula pipeline in fit to operate on Vector{AbstractTerm} with runtime column lookup (new src/utils/vectorterms.jl), so methods compile once per term type instead of once per formula shape and per set of column names. A regression with a never-seen formula now runs goes from ~0.28s to ~0.005s (~0.03s with fe), and the 10M-row benchmarks are also faster at runtime (fewer allocations from the preallocated model matrix).

  • Add vector-based replicas of schema/apply_schema (including stateful FullRank promotion)/modelcols/coefnames, plus vectorized parse_iv/parse_fe; the tuple-based versions are kept for partial_out and external users
  • Add @nospecialize to reg and to the FixedEffectModel constructor formula arguments
  • Cover categorical and interaction term types in the precompile workload; precompilation time is unchanged
  • Add a test that reg never modifies the input dataframe (model matrices are now built from views into it)
  • Update benchmark timings; bump version to 2.1.0

- Add utils/vectorterms.jl: replicas of the StatsModels schema/modelcols/coefnames
  pipeline operating on Vector{AbstractTerm} and runtime column lookup, so methods
  compile per term type rather than per formula shape or column names
- Rewire fit to the vector path (parsing, schema, model matrices, coefnames)
- Add @nospecialize to reg and to the FixedEffectModel constructor formula arguments
- Cover categorical and interaction term types in the precompile workload
- Test that reg never modifies the input dataframe
- Bump version to 2.1.0
@matthieugomez matthieugomez changed the title Reduce latency with vector-based formula machinery Reduce latency with vector-based formula Aug 28, 2026
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.07895% with 9 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@5edd010). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/utils/vectorterms.jl 91.58% 9 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #283   +/-   ##
=======================================
  Coverage        ?   96.70%           
=======================================
  Files           ?        9           
  Lines           ?      911           
  Branches        ?        0           
=======================================
  Hits            ?      881           
  Misses          ?       30           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Loading it up front invalidates the precompiled pipeline, inflating the
earlier first-call timings with recompilation
concrete_term fills ContinuousTerm's mean/var/min/max with three O(n) passes
per continuous column; nothing downstream reads them. Store NaN placeholders
instead (and build one schema shared by Y and X in partial_out), roughly
halving warm reg time on 10M-row benchmarks.
- Update benchmark.md with fresh timings for all four packages on the same machine (Apple M4): FixedEffectModels 2.1.0 / Julia 1.12.7, fixest 0.13.2 and lfe 3.1.1 on R 4.4.2, reghdfe 5.7.3 / ivreg2 4.1.11 on Stata 19 MP
- Regenerate the comparison graph and point benchmark.md to the repo png (the old rawgit link is dead)
- Restore newlines in benchmark.csv and result.jl (both had been mangled onto one line) and make result.jl read benchmark.csv relative to the script
- Refresh benchmark.jl timing comments after the schema speedup
- Remove the clustered-standard-errors claim from the README benchmark paragraph
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