Skip to content

Commit

Permalink
support/compressxdr: Fix compressxdr performance (#5494)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms authored Oct 15, 2024
1 parent c2849a0 commit 783bb05
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
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.

0 comments on commit 783bb05

Please sign in to comment.