Release the GVL when executing a prepared statement. #1
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 change allows the Ruby VM to continue executing other Ruby threads while the DuckDB prepared statement is being executed.
There are many other methods that are candidates for this same treatment. This PR addresses only execution of a prepared statement, which is also what
DuckDB::Connection#query
uses. If accepted, we could adopt a similar approach for other high-value functions.Ideally, we'd also be able to give Ruby the
duckdb_interrupt
function to handle signals, etc, but it seems there is nothing in the DuckDB C API that lets us interrupt a prepared statement, only a connection. (And it doesn't seem safe to interrupt a connection without reliably being able to know our given prepared statement is the active query on the connection.)Locally, this doesn't seem to have an effect on the performance of benchmarks, but presumably someone doing a whole lot of tiny transactions may be better able to detect it.
This fixes suketa#873 specifically, but we'll want to follow up with more if we determine this is a path we want to take.