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

Some performance and allocation optimizations #391

Merged
merged 7 commits into from
Oct 25, 2023
Merged

Conversation

yuyichao
Copy link
Contributor

#357 appears to increase the memory allocation for a problem I have by ~4x in number and ~1.7x in size. (It doesn't affect the constructed problem but it was affecting the overall performance on a somewhat memory constraint system (relative to the problem size))

Most of the allocations seems to be caused by unnecessary allocation of the array which is fixed in the second commit. The first and the third commits are some minor and easy optimizations I noticed while going through the code. These changes got the final allocation to be ~2x in number and ~1.1x in size.

The remaining additional allocation comes from the use of quadratic function to uniformly store all the constraints and objective information. (The extra allocation has two parts, one from the creation of the empty quadratic term vector when converting to a quadratic function and the other one from the index mapping for those terms at https://github.com/jump-dev/MathOptInterface.jl/blob/36ed9d8c8561d2fdc0cb7c1fe773566cbc0c7e29/src/Utilities/functions.jl#L315 ). This is fixed in the last commit by making the functions unions and rely on the union splitting from the compiler to deal with the resulting type instability. With this last commit, I got an allocation count/size that's basically the same as before.

@odow
Copy link
Member

odow commented Oct 25, 2023

Nice. I'll fix the formatting. I went for simplicity over performance with #357, and I figured it didn't matter because no one complained (until now 😄).

@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0eaf817) 94.06% compared to head (0582b64) 94.22%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #391      +/-   ##
==========================================
+ Coverage   94.06%   94.22%   +0.16%     
==========================================
  Files           4        4              
  Lines         927      953      +26     
==========================================
+ Hits          872      898      +26     
  Misses         55       55              
Files Coverage Δ
src/utils.jl 99.58% <100.00%> (+0.05%) ⬆️

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

@odow
Copy link
Member

odow commented Oct 25, 2023

Still happy?

@yuyichao
Copy link
Contributor Author

Yeah looks good to me.

@odow odow merged commit 84f4ed8 into jump-dev:master Oct 25, 2023
14 checks passed
@yuyichao yuyichao deleted the opt branch November 3, 2023 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants