reduce CGO call overhead for exec and bind paths#1386
Merged
Conversation
- Add _sqlite3_exec_no_args() C function that combines prepare+step+finalize into a single CGO crossing for parameterless exec (most common case) - Add _sqlite3_reset_clear() C function that combines sqlite3_reset and sqlite3_clear_bindings into a single CGO crossing - Use semaphore channel instead of result struct channel in context-aware exec/Next paths to reduce allocations - Use time.AppendFormat with stack buffer to avoid heap allocation in time.Time binding - Optimize bindNamedIndices to reuse a single buffer instead of 3 separate C.CString allocations - Remove intermediate bindIndices slice allocation in named parameter binding path - Pass explicit query length to sqlite3_prepare_v2 to avoid C-side strlen benchstat (n=8): BenchmarkExec: -29.44% sec/op, -50% B/op, -33% allocs/op BenchmarkQuery: -9.83% sec/op BenchmarkParams: -6.38% sec/op geomean: -6.72% sec/op
Move extern declarations for _sqlite3_*_blocking functions before _sqlite3_exec_no_args which references them. Remove unused _sqlite3_prepare_v2_nolen function.
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.
Combine multiple CGO crossings into single C calls for hot paths.
_sqlite3_exec_no_args(): merges prepare+step+finalize into one CGO call for parameterless exec (the most common case)_sqlite3_reset_clear(): merges sqlite3_reset + sqlite3_clear_bindings into one CGO calltime.AppendFormatwith stack buffer to avoid heap allocation when bindingtime.TimebindNamedIndicesinstead of 3C.CStringallocationsbindIndicesslice in named parameter bindingsqlite3_prepare_v2to skip C-sidestrlen