-
Notifications
You must be signed in to change notification settings - Fork 87
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
[FileFormats.MPS]: avoid creating list of variable names #2426
Conversation
I didn't think to test this. I just assumed that one list of strings would be better than needing to repeatedly query |
Querying |
Yeah, which explains the increase in allocations. But I guess they are short-lived. The GC just doesn't like long-lived GC objects. |
To clarify, the issue isn't creating one string per variable, the issue is having O(num_variable) strings in existence simultaneously. |
Yeah.
Is there a similar thing to do for the constraints? Perhaps just changing the |
We need a type-stable function mapping a |
I hacked at this a bit more, but the constraint side is harder than I expected. The problem is the string identifiers used in the constraint matrix transpose code: MathOptInterface.jl/src/FileFormats/MPS/MPS.jl Lines 479 to 481 in b64dbe1
I tried something like:
where we first breakdown by (F,S) then list the coefficients by column. This isn't great because requires a fair amount more memory usage and didn't seem to make things faster anyway. We really just want to have all constraint types to share the same index space and just do a sparse matrix transpose to get the column-wise format, similar to the type of manipulations that solver interfaces do. That's about as far as I can push for now. |
The flat linear constraint space was what I started to do in #2422. But now I know the big |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I made a small change. You should also try JuMP.set_string_names_on_creation(model, false)
.
Is the plan to land this instead of #2422? |
Fair enough. Do we know what's going on with the nightly CI failure? |
No, there have been a few failures. Also in MutableArithmetics: https://github.com/jump-dev/MutableArithmetics.jl/actions/runs/7892806791/job/21540090078?pr=257. I'll take a look. |
Your first commit to MOI in a while! |
The MPS writer has quadratic-ish performance because it creates GC-tracked strings for every variable and constraint. This PR shows one way we could skip this: generate the generic names on demand.
I didn't implement it for constraints because they need fancier code to deal with the constraint type parameters efficiently.
Potential alternatives:
Before:
After:
If we extrapolate, the version that does this approach for constraints would be around 70 sec, so we'd get a 2x speed up on this one example and better asymptotic performance.