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

wire: only borrow/return binaryFreeList buffers at the message level #2073

Merged
merged 52 commits into from
Dec 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b434080
wire/bench_test: report allocs in benchmarks
cfromknecht Jan 25, 2020
a9edc32
wire/bench: add witness block
cfromknecht Jan 25, 2020
a371aeb
wire/common: optimize Read/WriteVarInt
cfromknecht Jan 25, 2020
6275db9
wire: introduce Read/WriteVarIntBuf to reuse buffers between invocations
cfromknecht Jan 25, 2020
e58aadc
wire/msgtx: use Read/WriteVarIntBuf in tx serialization
cfromknecht Jan 25, 2020
e12d32d
wire/msgtx: reuse tx-level buffer for version and locktime
cfromknecht Jan 25, 2020
7951aa5
wire/common: add optimized Read/WriteVarBytesBuf
cfromknecht Jan 25, 2020
b171012
wire/msgtx: introduce optimized read/writeOutPointBuf
cfromknecht Jan 25, 2020
d43d9d5
wire/msgtx: introduce optimized writeTxInBuf
cfromknecht Jan 25, 2020
4829ff7
wire/msgtx: use writeTxInBuf in txn encoding
cfromknecht Jan 25, 2020
99f6488
wire/msgtx: introduce optimized readScriptBuf
cfromknecht Apr 30, 2019
6f4a7a1
wire/msgtx: introduce optimized readTxInBuf
cfromknecht Apr 30, 2019
607eea1
wire/msgtx: use readTxInBuf in txn serialization
cfromknecht Jan 25, 2020
7c8844f
wire/msgtx: introduce optimized WriteTxOutBuf
cfromknecht Jan 25, 2020
48d31e5
wire/msgtx: use WriteTxOutBuf in txn serialization
cfromknecht Jan 25, 2020
aebc743
wire/msgtx: introduce optimized readTxOutBuf
cfromknecht Jan 25, 2020
24d4217
wire/msgtx: use readTxOutBuf in txn serialization
cfromknecht Jan 25, 2020
3bfd0c6
wire/msgtx: introduce optimized writeTxWitnessBuf
cfromknecht Jan 25, 2020
3a91303
wire/msgtx: use writeTxWitnessBuf in txn serialization
cfromknecht Jan 25, 2020
0cf8c19
wire/msgtx: use readScriptBuf in txn serialization
cfromknecht Jan 25, 2020
aa769e3
wire/bench_test: introduce optimized readBlockHeaderBuf
cfromknecht Jan 25, 2020
3cee06e
wire/blockheader: introduce optimized writeBlockHeaderBuf
cfromknecht Jan 25, 2020
674c220
wire/invvect: add optimized readInvVectBuf and writeInvVectBuf
cfromknecht Jan 25, 2020
4ebc651
wire/msggetblocks: optimize by reusing small buffer
cfromknecht Jan 25, 2020
ee1f807
wire/msgblock: use only one small buffer per block encode/decode
cfromknecht Jan 25, 2020
d8e0817
wire/msgblock: optimize DeserializeTxLoc by reusing small buffers
cfromknecht Jan 25, 2020
c0d35e6
wire/msggetheaders: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
83675cb
wire/msgheaders: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
d042fe0
wire/msggetcfheaders: use single small buffer for encode/decode
cfromknecht Jan 25, 2020
1c525db
wire/msgcfheaders: optimize encode/decode by using one small buffer
cfromknecht Jan 25, 2020
1990555
wire/msggetcfcheckpt: optimize by removing read/writeElement
cfromknecht Jan 25, 2020
f37f475
wire/msgcfcheckpt: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
2383a04
wire/msginv: optimize by reusing small buffers
cfromknecht Jan 25, 2020
d6594da
wire/msggetdata: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
ddeba60
wiree/msggetcfilters: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
834febb
wire/msgcfilter: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
efcf964
wire/msgnotfound: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
1cd5e02
wire/invvect: remove unused readInvVect and writeInvVect
cfromknecht Jan 25, 2020
57daac3
wire/common: add optimized writeVarStrBuf an readVarStrBuf
cfromknecht Jan 25, 2020
dc4fbb0
wire/msgreject: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
8bf07cc
wire/netaddress: add optimiezed read/writeNetAddressBuf
cfromknecht Jan 25, 2020
7207967
wire/msgmerkleblock: optimize serialization by reusing small buffers
cfromknecht Jan 25, 2020
3698f2d
wire/msgping: remove usage for read/writeElement
cfromknecht Jan 25, 2020
80ae5d3
wire/msgpong: remove usage of read/writeElement
cfromknecht Jan 25, 2020
da89ed6
wire/msgtx: remove unused writeTxWitness
cfromknecht Jan 25, 2020
f0184e5
wire/msgtx: remove unused writeTxIn
cfromknecht Jan 25, 2020
e0fa866
wire/msgtx: remove unused readTxIn
cfromknecht Jan 25, 2020
4cc4f76
wire/msgtx: remove unused readScript
cfromknecht Jan 25, 2020
2e6eefc
wire/msgtx: remove unused read/writeOutPoint
cfromknecht Jan 25, 2020
d7396dc
wire/msgtx: use tx-level script slab
cfromknecht Jan 25, 2020
8c4da83
wire/msgblock+msgtx: user block-level script slab
cfromknecht Jan 25, 2020
b0e9636
wire: consistently use defer for returning scratch buffers
Roasbeef Dec 29, 2023
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
18 changes: 9 additions & 9 deletions wire/msgtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,10 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
func (msg *MsgTx) btcDecode(r io.Reader, pver uint32, enc MessageEncoding,
buf []byte) error {

version, err := binarySerializer.Uint32(r, littleEndian)
if err != nil {
if _, err := io.ReadFull(r, buf[:4]); err != nil {
return err
}
msg.Version = int32(version)
msg.Version = int32(littleEndian.Uint32(buf[:4]))

count, err := ReadVarIntBuf(r, pver, buf)
if err != nil {
Expand Down Expand Up @@ -635,11 +634,11 @@ func (msg *MsgTx) btcDecode(r io.Reader, pver uint32, enc MessageEncoding,
}
}

msg.LockTime, err = binarySerializer.Uint32(r, littleEndian)
if err != nil {
if _, err := io.ReadFull(r, buf[:4]); err != nil {
returnScriptBuffers()
return err
}
msg.LockTime = littleEndian.Uint32(buf[:4])

// Create a single allocation to house all of the scripts and set each
// input signature script and output public key script to the
Expand Down Expand Up @@ -751,8 +750,8 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
func (msg *MsgTx) btcEncode(w io.Writer, pver uint32, enc MessageEncoding,
buf []byte) error {

err := binarySerializer.PutUint32(w, littleEndian, uint32(msg.Version))
if err != nil {
littleEndian.PutUint32(buf[:4], uint32(msg.Version))
if _, err := w.Write(buf[:4]); err != nil {
return err
}

Expand All @@ -772,7 +771,7 @@ func (msg *MsgTx) btcEncode(w io.Writer, pver uint32, enc MessageEncoding,
}

count := uint64(len(msg.TxIn))
err = WriteVarIntBuf(w, pver, count, buf)
err := WriteVarIntBuf(w, pver, count, buf)
if err != nil {
return err
}
Expand Down Expand Up @@ -809,7 +808,8 @@ func (msg *MsgTx) btcEncode(w io.Writer, pver uint32, enc MessageEncoding,
}
}

err = binarySerializer.PutUint32(w, littleEndian, msg.LockTime)
littleEndian.PutUint32(buf[:4], msg.LockTime)
_, err = w.Write(buf[:4])
Roasbeef marked this conversation as resolved.
Show resolved Hide resolved
return err
}

Expand Down