Skip to content

Cache interpretation of trees and avoid excessive recomputation of predicates/trees - #91

Merged
Jekannadar merged 1 commit into
tudo-seal:developfrom
Jekannadar:feature/performance-tuning
Aug 13, 2026
Merged

Cache interpretation of trees and avoid excessive recomputation of predicates/trees#91
Jekannadar merged 1 commit into
tudo-seal:developfrom
Jekannadar:feature/performance-tuning

Conversation

@Jekannadar

@Jekannadar Jekannadar commented Aug 13, 2026

Copy link
Copy Markdown
Member

Adds a cache to the Tree class, _interpreted. Trees are immutable, as long as the interpretation is deterministic, having a cache on the Tree itself is fine.

Modify _generate_new_trees:

Currently, whenever it is called, it combines all arguments with all parameters, and then later duplicates are thrown away downstream.

_RuleProgress introduces some simple tracking, making sure to only compute new combinations:

  • new params with new args
  • new params with old args
  • new args with old params

This gets some speedup across all CoSy tests and benchmarks, CoSy-Luigi speeds up a bit, and on projects that are basically using CLS to compute a powerset, this gets a very heavy speedup.

Note:

  • For non-deterministic interpretations and predicates, this definitely is breaking. However, I could not come up with a use-case for those, you wouldn't use combinatory logic if you wanted to go to the Casino during inhabitation.
  • The dict containing the _RuleProgress objects is keyed on the id of RHSRule instead of itself. While RHSRule is hashable, its hash is rather expensive, and Pythons built-in id works just the same for this use-case.

@tudo-seal-workflows tudo-seal-workflows Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark CoSy

Details
Benchmark suite Current: b5a8825 Previous: be71b5d Ratio
benchmarks/test_benchmark_maximal_elements.py::test_benchmark_maximal_elements 10.43306182813801 iter/sec (stddev: 0.00022465880145587798) 9.608281351562356 iter/sec (stddev: 0.010017085420616013) 0.92
benchmarks/test_benchmark_maze.py::test_benchmark_maze 4.359626682760569 iter/sec (stddev: 0.020393723606656953) 3.9235166334572096 iter/sec (stddev: 0.018797551923491352) 0.90
benchmarks/test_benchmark_maze_contains.py::test_benchmark_maze_contains 4.110375478673194 iter/sec (stddev: 0.023216042955672603) 3.5391214334611916 iter/sec (stddev: 0.025877608823890046) 0.86
benchmarks/test_benchmark_maze_loopfree.py::test_benchmark_maze_loopfree 4.1489713872557 iter/sec (stddev: 0.024998383997361814) 3.8477221717914887 iter/sec (stddev: 0.02072136799063595) 0.93

This comment was automatically generated by workflow using github-action-benchmark.

@codecov-commenter

codecov-commenter commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.89041% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.02%. Comparing base (27f28d7) to head (b5a8825).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cosy/core/solution_space.py 88.88% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #91      +/-   ##
===========================================
+ Coverage    71.99%   73.02%   +1.03%     
===========================================
  Files           37       39       +2     
  Lines         2810     2944     +134     
  Branches       476      494      +18     
===========================================
+ Hits          2023     2150     +127     
- Misses         683      686       +3     
- Partials       104      108       +4     
Flag Coverage Δ
macos-latest-3.10 72.92% <95.89%> (+1.04%) ⬆️
macos-latest-3.11 72.99% <95.89%> (+1.14%) ⬆️
macos-latest-3.12 72.99% <95.89%> (+1.14%) ⬆️
macos-latest-3.13 72.79% <95.89%> (+0.83%) ⬆️
ubuntu-latest-3.10 72.82% <95.89%> (+1.26%) ⬆️
ubuntu-latest-3.11 72.99% <95.89%> (+1.10%) ⬆️
ubuntu-latest-3.12 72.99% <95.89%> (+1.03%) ⬆️
ubuntu-latest-3.13 72.99% <95.89%> (+1.14%) ⬆️
windows-latest-3.10 72.92% <95.89%> (+1.25%) ⬆️
windows-latest-3.11 72.99% <95.89%> (+1.03%) ⬆️
windows-latest-3.12 72.99% <95.89%> (+1.03%) ⬆️
windows-latest-3.13 72.99% <95.89%> (+1.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jekannadar
Jekannadar force-pushed the feature/performance-tuning branch 3 times, most recently from c6e2676 to 807c1fb Compare August 13, 2026 17:28
@Jekannadar
Jekannadar force-pushed the feature/performance-tuning branch from 807c1fb to b5a8825 Compare August 13, 2026 17:31
@Jekannadar
Jekannadar merged commit 2e318a2 into tudo-seal:develop Aug 13, 2026
14 checks passed
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.

2 participants