Skip to content

Optimize getLedgers queries by only decoding the header#505

Merged
Shaptic merged 8 commits intomainfrom
getLedgers_depthCheck
Sep 11, 2025
Merged

Optimize getLedgers queries by only decoding the header#505
Shaptic merged 8 commits intomainfrom
getLedgers_depthCheck

Conversation

@Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Aug 27, 2025

What

Instead of decoding the raw binary data directly into an xdr.LedgerCloseMeta, this modifies the code to only decode the xdr.LedgerHeaderHistoryEntry out of the data which comes first in the layout. The rest of the meta is passed around directly as a []byte until the final step, either converting it to base64 directly or to JSON.

Rudimentary benchmarks show a ~40% improvement over the baseline:

$ git switch main
$ go test -failfast -run=None -bench=BenchmarkBatchGetLedgers ./cmd/stellar-rpc/internal/db
BenchmarkBatchGetLedgers-16    	1788	    773248 ns/op
ok  	github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/db	7.652s

$ git switch getLedgers_depthCheck
$ go test -failfast -run=None -bench=BenchmarkBatchGetLedgers ./cmd/stellar-rpc/internal/db
BenchmarkBatchGetLedgers-16    	    1939	    530915 ns/op
ok  	github.com/stellar/stellar-rpc/cmd/stellar-rpc/internal/db	3.325s

Why

We have observed performance issues with getLedgers due to their density and would like to improve them.

Known limitations

This needs to be evaluated against real load to see the improvement.

@Shaptic Shaptic marked this pull request as ready for review September 5, 2025 01:03
@Shaptic Shaptic requested a review from a team September 5, 2025 17:29
Copy link
Contributor

@sreuland sreuland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

novel solution, nice work!

Copy link
Contributor

@tamirms tamirms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job!

@Shaptic Shaptic enabled auto-merge (squash) September 9, 2025 17:39
@Shaptic Shaptic merged commit 0141792 into main Sep 11, 2025
17 of 19 checks passed
@Shaptic Shaptic deleted the getLedgers_depthCheck branch September 11, 2025 01:33
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.

3 participants