feat(tokens): prepare UnspentTokensIteratorBy statements by argument shape#1889
Open
sid200727 wants to merge 1 commit into
Open
feat(tokens): prepare UnspentTokensIteratorBy statements by argument shape#1889sid200727 wants to merge 1 commit into
sid200727 wants to merge 1 commit into
Conversation
…shape Introduces on-demand prepared-statement caching for UnspentTokensIteratorBy, keyed by argument shape (walletID present/absent, tokenType present/absent). The 3 shapes that occur in production (see call-site analysis on LFDT-Panurus#1183) are each prepared once and reused; anything outside that set falls back to the existing dynamic query-building path. Benchmarked in LFDT-Panurus#1855: +11% throughput, -73% P99 latency, -80% allocs/op (prepared vs dynamic, median of 3 runs). Closes LFDT-Panurus#1183 Signed-off-by: Siddhi Khandelwal <siddhi.200727@gmail.com>
101a3d7 to
84fd06c
Compare
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
Implements prepared statements for
UnspentTokensIteratorByper the design discussed on #1183, following the benchmark work in #1855 that measured the win (+11% throughput, -73% P99 latency, -80% allocs/op).Changes
-> Added on-demand prepared-statement caching to
TokenStore, keyed by argument shape (walletIDpresent/absent,tokenTypepresent/absent)-> The 3 shapes that occur in current production call sites (documented on #1183) are each prepared once on first use and reused for all subsequent calls of that shape
-> Any call falling outside those 3 shapes (shouldn't happen given today's callers, but handled defensively) falls back to the existing dynamic query-building path, same for any prepare/execute error, so this degrades gracefully rather than failing
->
Close()now closes all cached prepared statements before closing the DB connectionsDesign notes
newTokenStorehas no context/error return today and eager preparation would ripple that signature change through every constructor caller. Happy to revisit if eager preparation is preferred.walletID present?,tokenType present?), not the argument values themselves, statements are shared across different wallet/type values of the same shape.Testing
-> New unit test (
tokens_prepared_test.goincommon) covers the shape-key logic directly-> New integration test (
tokens_prepared_test.goinpostgres) verifies statement reuse across repeated/varied calls of the same shape, and distinct caching per shape, against real Postgres-> Existing
TestTokenssuite passes unchanged on both sqlite and postgresCloses #1183