Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support/compressxdr: Fix compressxdr performance #5494

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).

- Improved performance of requests which query the lower boundary of horizon's history when running a horizon instance with the `--history-retention-count` flag. ([5410](https://github.com/stellar/go/pull/5410), [5448](https://github.com/stellar/go/pull/5448), [5465](https://github.com/stellar/go/pull/5465))

- Improve performance of ingestion when running horizon with the `--history-retention-count` flag by executing reaping of history lookup tables concurrently with ingestion ([5405](https://github.com/stellar/go/pull/5405)).
- Improve performance of ingestion when running horizon with the `--history-retention-count` flag by executing reaping of history lookup tables concurrently with ingestion. ([5405](https://github.com/stellar/go/pull/5405))

- Improve performance of ingestion when consuming ledgers via the BufferedStorageBackend. ([5494](https://github.com/stellar/go/pull/5494))

## 2.32.0

Expand Down
6 changes: 3 additions & 3 deletions support/compressxdr/compress_xdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package compressxdr
import (
"io"

xdr3 "github.com/stellar/go-xdr/xdr3"
"github.com/stellar/go/xdr"
)

func NewXDREncoder(compressor Compressor, xdrPayload interface{}) XDREncoder {
Expand All @@ -29,7 +29,7 @@ func (e XDREncoder) WriteTo(w io.Writer) (int64, error) {
}
defer zw.Close()

n, err := xdr3.Marshal(zw, e.XdrPayload)
n, err := xdr.Marshal(zw, e.XdrPayload)
return int64(n), err
}

Expand All @@ -47,6 +47,6 @@ func (d XDRDecoder) ReadFrom(r io.Reader) (int64, error) {
}
defer zr.Close()

n, err := xdr3.Unmarshal(zr, d.XdrPayload)
n, err := xdr.Unmarshal(zr, d.XdrPayload)
return int64(n), err
}
36 changes: 35 additions & 1 deletion support/compressxdr/compress_xdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package compressxdr

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/stellar/go/xdr"
"github.com/stretchr/testify/require"

"github.com/stellar/go/xdr"
)

func createTestLedgerCloseMetaBatch(startSeq, endSeq uint32, count int) xdr.LedgerCloseMetaBatch {
Expand Down Expand Up @@ -46,3 +49,34 @@ func TestEncodeDecodeLedgerCloseMetaBatch(t *testing.T) {
require.Equal(t, testData.LedgerCloseMetas[i], decodedData.LedgerCloseMetas[i])
}
}

func BenchmarkDecodeLedgerCloseMetaBatch(b *testing.B) {
lcmBatch := xdr.LedgerCloseMetaBatch{}
decoder := NewXDRDecoder(DefaultCompressor, &lcmBatch)

for n := 0; n < b.N; n++ {
file, err := os.Open("testdata/FCD285FF--53312000.xdr.zstd")
require.NoError(b, err)

_, err = decoder.ReadFrom(file)
require.NoError(b, err)
}
}

func BenchmarkEncodeLedgerCloseMetaBatch(b *testing.B) {
lcmBatch := xdr.LedgerCloseMetaBatch{}
decoder := NewXDRDecoder(DefaultCompressor, &lcmBatch)
file, err := os.Open("testdata/FCD285FF--53312000.xdr.zstd")
require.NoError(b, err)

_, err = decoder.ReadFrom(file)
require.NoError(b, err)

b.ResetTimer()

for n := 0; n < b.N; n++ {
encoder := NewXDREncoder(DefaultCompressor, &lcmBatch)
_, err = encoder.WriteTo(ioutil.Discard)
require.NoError(b, err)
}
}
Binary file not shown.
Loading