Replace Computable Descriptor with @computed in mesa_signals#3153
Merged
Replace Computable Descriptor with @computed in mesa_signals#3153
Conversation
|
Performance benchmarks:
|
codebreaker32
commented
Jan 16, 2026
quaquel
reviewed
Jan 16, 2026
quaquel
reviewed
Jan 16, 2026
Member
|
I ran some quick tests locally. It seems this implementation is much faster because it eliminates significant overhead. I also think the API is much cleaner. I'll try to review in more detail soon. In the meantime, can you check the code coverage report and see if you can add additional tests to ensure we have close to 100% coverage? |
Collaborator
Author
Done |
quaquel
approved these changes
Jan 17, 2026
Member
|
Thanks again for this PR. A very nice improvement. |
quaquel
pushed a commit
to quaquel/mesa
that referenced
this pull request
Jan 18, 2026
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.
This PR modifies
mesa_signalsto move from a class-based descriptor pattern (Computable/Computed) to a standard Python property factory (@computed).Currently, accessing a derived property triggers the
Computable.__get__descriptor, which then fetches a separateComputedobject to execute the logic. This adds unnecessary function call depth to every attribute access.I suggest two streamlined components:
@computedDecorator: A factory that returns a standard Pythonproperty. The "reactive" logic (dependency tracking, dirty checking) is captured in the property's closure, eliminating the descriptor lookup overhead.ComputedState: A lightweight, internal-only class using__slots__to hold the value, dirty flag, and dependencies.ComputedProperty: A custom property class to identify computed properties.API Changes (Before vs. After)
Before (Current)
After
Addresses (2) from #3131