perf: store example DB as fixtures, 850x faster export#651
Merged
Conversation
export_examples took ~34s in debug mode because every build ran
BruteForce on 72 examples. Now pre-computed results are embedded
as JSON fixtures via include_str!, reducing export to ~0.04s.
- Split build_*_db() (fixture load, fast) from compute_*_db() (BruteForce)
- Add fixture files: src/example_db/fixtures/{models,rules}.json
- Add regenerate_fixtures binary for updating fixtures when code changes
- Add verification tests comparing fixtures against freshly computed results
- Add `make regenerate-fixtures` target
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #651 +/- ##
========================================
Coverage 96.88% 96.88%
========================================
Files 268 269 +1
Lines 35563 36036 +473
========================================
+ Hits 34456 34915 +459
- Misses 1107 1121 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR speeds up example DB usage by embedding precomputed model/rule example databases as compile-time JSON fixtures, while keeping the original (slow) computation path for regeneration and verification.
Changes:
- Load example DBs from embedded
include_str!fixtures (build_*_db) and keep recomputation via builders (compute_*_db). - Add fixture regeneration example binary and fixture verification tests.
- Update Makefile/Cargo examples to support fixture regeneration and faster example export.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/example_db/mod.rs |
Splits “build from fixtures” vs “compute from builders” and updates public API accordingly. |
src/example_db/fixtures/models.json |
Adds embedded precomputed model example DB fixture. |
src/example_db/fixtures/rules.json |
Adds embedded precomputed rule example DB fixture. |
src/unit_tests/example_db.rs |
Adds tests to verify fixtures against freshly computed results. |
examples/regenerate_fixtures.rs |
Adds a binary to recompute and write fixture JSON files. |
Makefile |
Adds targets/help text for fixture regeneration and updates example export commands. |
Cargo.toml |
Registers the new regenerate_fixtures example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
127
to
130
| # Regenerate example DB fixtures from code (runs BruteForce/ILP — slow) | ||
| regenerate-fixtures: | ||
| cargo run --release --features "example-db" --example regenerate_fixtures | ||
|
|
Comment on lines
+24
to
+28
| let models_json = serde_json::to_string(&model_db).expect("Failed to serialize models"); | ||
| let rules_json = serde_json::to_string(&rule_db).expect("Failed to serialize rules"); | ||
|
|
||
| fs::write(&models_path, &models_json).expect("Failed to write models fixture"); | ||
| fs::write(&rules_path, &rules_json).expect("Failed to write rules fixture"); |
Comment on lines
+66
to
+71
| pub fn build_model_db() -> Result<ModelDb> { | ||
| static MODELS_JSON: &str = include_str!("fixtures/models.json"); | ||
| let db: ModelDb = | ||
| serde_json::from_str(MODELS_JSON).expect("embedded models fixture should parse"); | ||
| validate_model_uniqueness(&db.models)?; | ||
| Ok(db) |
Comment on lines
+75
to
+80
| pub fn build_rule_db() -> Result<RuleDb> { | ||
| let mut rules = rule_builders::build_rule_examples(); | ||
| rules.sort_by_key(rule_key); | ||
| validate_rule_uniqueness(&rules)?; | ||
| Ok(RuleDb { | ||
| version: EXAMPLE_DB_VERSION, | ||
| rules, | ||
| }) | ||
| static RULES_JSON: &str = include_str!("fixtures/rules.json"); | ||
| let db: RuleDb = | ||
| serde_json::from_str(RULES_JSON).expect("embedded rules fixture should parse"); | ||
| validate_rule_uniqueness(&db.rules)?; | ||
| Ok(db) |
Comment on lines
+271
to
+278
| for (loaded_model, computed_model) in loaded.models.iter().zip(computed.models.iter()) { | ||
| assert_eq!( | ||
| loaded_model, computed_model, | ||
| "model fixture mismatch for {} {:?} — regenerate fixtures with: \ | ||
| cargo run --release --example regenerate_fixtures --features example-db", | ||
| loaded_model.problem, loaded_model.variant | ||
| ); | ||
| } |
Comment on lines
+304
to
+323
| for (loaded_rule, computed_rule) in loaded.rules.iter().zip(computed.rules.iter()) { | ||
| assert_eq!( | ||
| loaded_rule.solutions.len(), | ||
| computed_rule.solutions.len(), | ||
| "solution count mismatch for {} -> {} — regenerate fixtures", | ||
| loaded_rule.source.problem, loaded_rule.target.problem | ||
| ); | ||
| // Overhead formulas may differ between debug/release due to | ||
| // floating-point path-cost differences in path-based examples. | ||
| // Just verify the same set of overhead field names exist. | ||
| let loaded_fields: BTreeSet<_> = | ||
| loaded_rule.overhead.iter().map(|o| &o.field).collect(); | ||
| let computed_fields: BTreeSet<_> = | ||
| computed_rule.overhead.iter().map(|o| &o.field).collect(); | ||
| assert_eq!( | ||
| loaded_fields, computed_fields, | ||
| "overhead fields mismatch for {} -> {} — regenerate fixtures", | ||
| loaded_rule.source.problem, loaded_rule.target.problem | ||
| ); | ||
| } |
| @echo " examples - Generate example JSON for paper" | ||
| @echo " examples - Generate example JSON for paper (from fixtures, fast)" | ||
| @echo " regenerate-fixtures - Recompute example DB fixtures (BruteForce/ILP, slow)" | ||
| @echo " regenerate-fixtures - Recompute example DB fixtures (BruteForce/ILP, slow)" |
- Add negation rule in .gitignore so src/example_db/fixtures/*.json is tracked (fixes CI build failure: include_str! could not find the file) - Replace expect() with proper ProblemError::SerializationError in build_example_db() fixture parsing - Cache computed rule DB in tests via OnceLock to avoid redundant work Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
export_examplestook ~34s in debug mode because every build ran BruteForce on 72 examplesinclude_str!, reducing export to ~0.04s (850x speedup)compute_*_db()functions preserved for fixture regeneration and verification testsChanges
build_*_db()(fast fixture load) fromcompute_*_db()(BruteForce/ILP computation)src/example_db/fixtures/{models,rules}.json— pre-computed expected resultsexamples/regenerate_fixtures.rsbinary for updating fixtures when models/rules changeverify_model_fixtures_match_computedandverify_rule_fixtures_match_computedtestsmake regenerate-fixturesMakefile targetTest plan
cargo test --features "ilp-highs example-db")export_examplesruns in 0.04s (was 34s)make regenerate-fixturesworks correctly🤖 Generated with Claude Code