Skip to content

Commit 783bb05

Browse files
authored
support/compressxdr: Fix compressxdr performance (#5494)
1 parent c2849a0 commit 783bb05

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

services/horizon/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
3232

3333
- 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))
3434

35-
- 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)).
35+
- 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))
36+
37+
- Improve performance of ingestion when consuming ledgers via the BufferedStorageBackend. ([5494](https://github.com/stellar/go/pull/5494))
3638

3739
## 2.32.0
3840

support/compressxdr/compress_xdr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package compressxdr
33
import (
44
"io"
55

6-
xdr3 "github.com/stellar/go-xdr/xdr3"
6+
"github.com/stellar/go/xdr"
77
)
88

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

32-
n, err := xdr3.Marshal(zw, e.XdrPayload)
32+
n, err := xdr.Marshal(zw, e.XdrPayload)
3333
return int64(n), err
3434
}
3535

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

50-
n, err := xdr3.Unmarshal(zr, d.XdrPayload)
50+
n, err := xdr.Unmarshal(zr, d.XdrPayload)
5151
return int64(n), err
5252
}

support/compressxdr/compress_xdr_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package compressxdr
22

33
import (
44
"bytes"
5+
"io/ioutil"
6+
"os"
57
"testing"
68

7-
"github.com/stellar/go/xdr"
89
"github.com/stretchr/testify/require"
10+
11+
"github.com/stellar/go/xdr"
912
)
1013

1114
func createTestLedgerCloseMetaBatch(startSeq, endSeq uint32, count int) xdr.LedgerCloseMetaBatch {
@@ -46,3 +49,34 @@ func TestEncodeDecodeLedgerCloseMetaBatch(t *testing.T) {
4649
require.Equal(t, testData.LedgerCloseMetas[i], decodedData.LedgerCloseMetas[i])
4750
}
4851
}
52+
53+
func BenchmarkDecodeLedgerCloseMetaBatch(b *testing.B) {
54+
lcmBatch := xdr.LedgerCloseMetaBatch{}
55+
decoder := NewXDRDecoder(DefaultCompressor, &lcmBatch)
56+
57+
for n := 0; n < b.N; n++ {
58+
file, err := os.Open("testdata/FCD285FF--53312000.xdr.zstd")
59+
require.NoError(b, err)
60+
61+
_, err = decoder.ReadFrom(file)
62+
require.NoError(b, err)
63+
}
64+
}
65+
66+
func BenchmarkEncodeLedgerCloseMetaBatch(b *testing.B) {
67+
lcmBatch := xdr.LedgerCloseMetaBatch{}
68+
decoder := NewXDRDecoder(DefaultCompressor, &lcmBatch)
69+
file, err := os.Open("testdata/FCD285FF--53312000.xdr.zstd")
70+
require.NoError(b, err)
71+
72+
_, err = decoder.ReadFrom(file)
73+
require.NoError(b, err)
74+
75+
b.ResetTimer()
76+
77+
for n := 0; n < b.N; n++ {
78+
encoder := NewXDREncoder(DefaultCompressor, &lcmBatch)
79+
_, err = encoder.WriteTo(ioutil.Discard)
80+
require.NoError(b, err)
81+
}
82+
}
Binary file not shown.

0 commit comments

Comments
 (0)