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

Release the GVL when executing a prepared statement. #1

Closed
wants to merge 1 commit into from

Conversation

doxavore
Copy link
Member

@doxavore doxavore commented Feb 6, 2025

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.

@doxavore doxavore self-assigned this Feb 6, 2025
@doxavore doxavore force-pushed the without-gvl branch 2 times, most recently from 534268b to c67e688 Compare February 7, 2025 00:00
This change allows the Ruby VM to continue executing other Ruby threads
while the DuckDB prepared statement is being executed.
@doxavore doxavore marked this pull request as ready for review February 11, 2025 19:57
@doxavore
Copy link
Member Author

Accepted upstream.

@doxavore doxavore closed this Feb 12, 2025
@doxavore doxavore deleted the without-gvl branch February 12, 2025 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ruby threads blocked on calls to C functions
1 participant