Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid superfluous DB calls from facade #149

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

glatterf42
Copy link
Member

While working on #148, @meksor and I noted that there were always two calls to validate_data when adding data to a Parameter. This is superfluous, of course, and the culprit is in the core layer: in parameter.add(), we add_data(), but then also set parameter._model.data, which triggers another validate_data() run because that always fires when the attribute is set.

This PR fixes that by setting parameter._model instead of just .data, also for all other relevant optimization items. This significantly boosts their performance.

@glatterf42 glatterf42 added the enhancement New feature or request label Jan 16, 2025
@glatterf42 glatterf42 requested a review from meksor January 16, 2025 11:12
@glatterf42 glatterf42 self-assigned this Jan 16, 2025
@glatterf42 glatterf42 marked this pull request as ready for review January 16, 2025 11:12
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.9%. Comparing base (0deac5b) to head (007950e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #149     +/-   ##
=======================================
- Coverage   86.9%   86.9%   -0.1%     
=======================================
  Files        230     230             
  Lines       8156    8156             
=======================================
- Hits        7095    7094      -1     
- Misses      1061    1062      +1     
Files with missing lines Coverage Δ
ixmp4/core/optimization/equation.py 93.5% <100.0%> (ø)
ixmp4/core/optimization/indexset.py 91.5% <100.0%> (ø)
ixmp4/core/optimization/parameter.py 93.3% <100.0%> (ø)
ixmp4/core/optimization/table.py 92.5% <100.0%> (ø)
ixmp4/core/optimization/variable.py 93.6% <100.0%> (ø)

... and 1 file with indirect coverage changes

Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

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

Nice! Thank you!

I now remember that I noticed this issue a while back in the tests but didn't manage to solve it at the time...

@glatterf42 glatterf42 merged commit c243743 into main Jan 16, 2025
13 checks passed
@glatterf42 glatterf42 deleted the fix/avoid-superfluous-db-calls-from-core branch January 16, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants