Release the GVL during routing model setup - #87
Closed
erickreutz wants to merge 1 commit into
Closed
erickreutz wants to merge 1 commit into
erickreutz wants to merge 1 commit into
Conversation
Allow Ruby threads to keep running while callback-free routing models close and restore route assignments. Keep the GVL when Ruby transit callbacks may execute.
ankane
added a commit
that referenced
this pull request
Oct 1, 2026
Co-authored-by: Eric Kreutzer <eric@lugg.com>
Owner
|
Hi @erickreutz, thanks for the PR. Merged a version of this for |
Contributor
Author
|
Thanks for merging that! We checked the last 24 hours in production. Across 10,665 The long stalls were in |
Owner
|
Thanks for checking. Will hold off on updating |
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.
RoutingModel#close_modeland#read_assignment_from_routescan spend significant time in native OR-Tools code, but unlike the existing solve wrappers, they currently hold Ruby's GVL for the entire call. This adds callback-aware wrappers that release the GVL during those operations when the routing model uses only native callbacks.The safety boundary matches the solve path: models with Ruby transit callbacks retain the GVL, while native vector and matrix callbacks allow other Ruby threads to run. Route arrays are converted to owned C++ values before the GVL is released, and returned assignments are wrapped after Ruby execution resumes. The raw callback, solve, close, and restoration entry points are private so callers cannot bypass the callback gate.
The coverage exercises Ruby thread progress during both native calls, callback gating and exceptions, result parity, route conversion ownership, overlapping reads on separate models, and assignment lifetime. Existing routing results and callback behavior are unchanged.