You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
3.1 KiB

internal/libs/protoio: optimize MarshalDelimited by plain byteslice allocations+sync.Pool (#7325) Noticed in profiles that invoking *VoteSignBytes always created a bytes.Buffer, then discarded it inside protoio.MarshalDelimited. I dug further and examined the call paths and noticed that we unconditionally create the bytes.Buffer, even though we might have proto messages (in the common case) that implement MarshalTo([]byte), and invoked varintWriter. Instead by inlining this case, we skip a bunch of allocations and CPU cycles, which then reflects properly on all calling functions. Here are the benchmark results: ```shell $ benchstat before.txt after.txt name old time/op new time/op delta types.VoteSignBytes-8 705ns ± 3% 573ns ± 6% -18.74% (p=0.000 n=18+20) types.CommitVoteSignBytes-8 8.15µs ± 9% 6.81µs ± 4% -16.51% (p=0.000 n=20+19) protoio.MarshalDelimitedWithMarshalTo-8 788ns ± 8% 772ns ± 3% -2.01% (p=0.050 n=20+20) protoio.MarshalDelimitedNoMarshalTo-8 989ns ± 4% 845ns ± 2% -14.51% (p=0.000 n=20+18) name old alloc/op new alloc/op delta types.VoteSignBytes-8 792B ± 0% 600B ± 0% -24.24% (p=0.000 n=20+20) types.CommitVoteSignBytes-8 9.52kB ± 0% 7.60kB ± 0% -20.17% (p=0.000 n=20+20) protoio.MarshalDelimitedNoMarshalTo-8 808B ± 0% 440B ± 0% -45.54% (p=0.000 n=20+20) name old allocs/op new allocs/op delta types.VoteSignBytes-8 13.0 ± 0% 10.0 ± 0% -23.08% (p=0.000 n=20+20) types.CommitVoteSignBytes-8 140 ± 0% 110 ± 0% -21.43% (p=0.000 n=20+20) protoio.MarshalDelimitedNoMarshalTo-8 10.0 ± 0% 7.0 ± 0% -30.00% (p=0.000 n=20+20) ``` Thanks to Tharsis who tasked me to help them increase TPS and who are keen on improving Tendermint and efficiency.
3 years ago
  1. # Unreleased Changes
  2. Friendly reminder: We have a [bug bounty program](https://hackerone.com/cosmos).
  3. ## vX.X
  4. Month, DD, YYYY
  5. Special thanks to external contributors on this release:
  6. ### BREAKING CHANGES
  7. - CLI/RPC/Config
  8. - [rpc] \#7575 Rework how RPC responses are written back via HTTP. (@creachadair)
  9. - [rpc] \#7121 Remove the deprecated gRPC interface to the RPC service. (@creachadair)
  10. - [blocksync] \#7159 Remove support for disabling blocksync in any circumstance. (@tychoish)
  11. - [mempool] \#7171 Remove legacy mempool implementation. (@tychoish)
  12. - Apps
  13. - [proto/tendermint] \#6976 Remove core protobuf files in favor of only housing them in the [tendermint/spec](https://github.com/tendermint/spec) repository.
  14. - P2P Protocol
  15. - [p2p] \#7035 Remove legacy P2P routing implementation and associated configuration options. (@tychoish)
  16. - [p2p] \#7265 Peer manager reduces peer score for each failed dial attempts for peers that have not successfully dialed. (@tychoish)
  17. - [p2p] [\#7594](https://github.com/tendermint/tendermint/pull/7594) always advertise self, to enable mutual address discovery. (@altergui)
  18. - Go API
  19. - [rpc] \#7474 Remove the "URI" RPC client. (@creachadair)
  20. - [libs/pubsub] \#7451 Internalize the pubsub packages. (@creachadair)
  21. - [libs/sync] \#7450 Internalize and remove the library. (@creachadair)
  22. - [libs/async] \#7449 Move library to internal. (@creachadair)
  23. - [pubsub] \#7231 Remove unbuffered subscriptions and rework the Subscription interface. (@creachadair)
  24. - [eventbus] \#7231 Move the EventBus type to the internal/eventbus package. (@creachadair)
  25. - [blocksync] \#7046 Remove v2 implementation of the blocksync service and recactor, which was disabled in the previous release. (@tychoish)
  26. - [p2p] \#7064 Remove WDRR queue implementation. (@tychoish)
  27. - [config] \#7169 `WriteConfigFile` now returns an error. (@tychoish)
  28. - [libs/service] \#7288 Remove SetLogger method on `service.Service` interface. (@tychoish)
  29. - [abci/client] \#7607 Simplify client interface (removes most "async" methods). (@creachadair)
  30. - Blockchain Protocol
  31. ### FEATURES
  32. - [rpc] [\#7270](https://github.com/tendermint/tendermint/pull/7270) Add `header` and `header_by_hash` RPC Client queries. (@fedekunze)
  33. - [cli] [#7033](https://github.com/tendermint/tendermint/pull/7033) Add a `rollback` command to rollback to the previous tendermint state in the event of non-determinstic app hash or reverting an upgrade.
  34. - [mempool, rpc] \#7041 Add removeTx operation to the RPC layer. (@tychoish)
  35. ### IMPROVEMENTS
  36. - [internal/protoio] \#7325 Optimized `MarshalDelimited` by inlining the common case and using a `sync.Pool` in the worst case. (@odeke-em)
  37. - [pubsub] \#7319 Performance improvements for the event query API (@creachadair)
  38. - [node] \#7521 Define concrete type for seed node implementation (@spacech1mp)
  39. - [rpc] \#7612 paginate mempool /unconfirmed_txs rpc endpoint (@spacech1mp)
  40. - [light] [\#7536](https://github.com/tendermint/tendermint/pull/7536) rpc /status call returns info about the light client (@jmalicevic)
  41. ### BUG FIXES
  42. - fix: assignment copies lock value in `BitArray.UnmarshalJSON()` (@lklimek)