perf: cache Postgres prepared statements#139
Merged
Merged
Conversation
Contributor
Greptile SummaryThis PR caches prepared statements for pooled Postgres calls. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "fix: recover stale Postgres cached plans" | Re-trigger Greptile |
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.
Summary
prepare_cached()forquery,query_one, andexecuteBenchmark
Local Postgres 16 container,
wrk -t4 -c32 -d4s, same temporary ntnt app/fixtures, branch vsorigin/main.Pooled query routes improved roughly 2.0–2.36x; JSON/no-DB routes stayed flat, and per-request
connect(...)routes stayed bottlenecked as expected.Representative results:
NTNT_WORKERS=1,/db/pooled-single: 7,548.7 → 15,625.0 rps (2.07x), latency 4.19ms → 2.01msNTNT_WORKERS=1,/db/pooled-twenty: 428.4 → 1,011.1 rps (2.36x), latency 73.95ms → 31.52msNTNT_WORKERS=8,/db/pooled-single: 32,003.7 → 62,197.8 rps (1.94x), latency 0.99ms → 0.51msNTNT_WORKERS=8,/db/pooled-twenty: 2,092.2 → 4,735.9 rps (2.26x), latency 15.26ms → 6.75msVerification
cargo fmtcargo build --profile dev-releasecargo test --lib -qcargo test --test language_features_tests --test type_checker_tests --test cli_tests./target/dev-release/ntnt docs --generatecargo test -qgit diff --checkorigin/mainand this branch