perf: read block times from storage instead of the indexer - #62
Merged
Conversation
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.
Closes #34.
After the earlier fixes, list endpoints were still slow against the live deployment:
Measuring rather than guessing found it was not our box — mygnoscan had used 4.3s of CPU total since restart, and the local indexer answered in 1ms. It was upstream: the public topaz indexer answers in ~0.25s per request, and
stampBlockTimesasks it once per distinct block. A page spanning 50 blocks therefore spends well over a second on timestamps alone, and that is the whole difference.The syncer has been storing
block_timeon every transaction it writes all along, and after #55 and #59 that coverage extends to historical rows too. So the indexer never needed to be asked for most of them.stampBlockTimesnow reads fromtransactionsfirst and only queries the indexer for heights it does not already know — typically the handful of blocks newer than the last sync pass. For a fully-synced network that is zero indexer round trips where there used to be one per block.Being a method on
APIrather than a free function is what gives it database access; the network is passed explicitly so the lookup stays network-scoped.Tests
BlockTimesForHeightsreturns stored times, scopes to the network, and — the important part — omits heights with an empty or missing time rather than returning a blank string. That is what lets the caller ask the indexer for exactly the gap instead of assuming it has everything.Note
Absolute numbers on the deployment are noisy at the moment: the box is running a validator at ~100% CPU, and the public topaz indexers own latency varies by 5x between samples. The structural change — one query instead of N network round trips — is what matters here, and it is what remained of #34.