tendermint/types
Emmanuel Odeke 15ef57c6d0
types: TxEventBuffer.Flush now uses capacity preserving slice clearing idiom
Fixes https://github.com/tendermint/tendermint/issues/1189

For every TxEventBuffer.Flush() invoking, we were invoking
a:
  b.events = make([]EventDataTx, 0, b.capacity)
whose intention is to innocently clear the events slice but
maintain the underlying capacity.

However, unfortunately this is memory and garbage collection intensive
which is linear in the number of events added. If an attack had access
to our code somehow, invoking .Flush() in tight loops would be a sure
way to cause huge GC pressure, and say if they added about 1e9
events maliciously, every Flush() would take at least 3.2seconds
which is enough to now control our application.

The new using of the capacity preserving slice clearing idiom
takes a constant time regardless of the number of elements with zero
allocations so we are killing many birds with one stone i.e
  b.events = b.events[:0]

For benchmarking results, please see
https://gist.github.com/odeke-em/532c14ab67d71c9c0b95518a7a526058
for a reference on how things can get out of hand easily.
2018-02-05 23:34:15 -08:00
..
block.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
block_meta.go types: comments 2017-09-22 12:00:37 -04:00
block_test.go fixes from rebase 2017-12-26 20:42:34 -05:00
canonical_json.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
event_buffer.go types: TxEventBuffer.Flush now uses capacity preserving slice clearing idiom 2018-02-05 23:34:15 -08:00
event_buffer_test.go new pubsub package 2017-10-30 00:32:22 -05:00
event_bus.go update types 2018-02-03 03:23:10 -05:00
event_bus_test.go fixes from Bucky's and Emmanuel's reviews 2017-10-30 11:12:01 -05:00
events.go move fireEvents to ApplyBlock 2017-12-28 23:15:54 -05:00
evidence.go update types 2018-02-03 03:23:10 -05:00
evidence_test.go fixes from rebase 2017-12-26 20:42:34 -05:00
genesis.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
genesis_test.go Updates -> ValidatoSetUpdates 2017-12-19 13:03:39 -06:00
heartbeat.go update for sdk2 libs. need to fix kv test 2018-02-03 03:35:02 -05:00
heartbeat_test.go pass tests! 2017-11-27 22:39:12 +00:00
keys.go types: comments 2017-09-22 12:00:37 -04:00
nop_event_bus.go new pubsub package 2017-10-30 00:32:22 -05:00
params.go update types 2018-02-03 03:23:10 -05:00
params_test.go fix test 2017-12-21 17:52:06 -05:00
part_set.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
part_set_test.go all: no more anonymous imports 2017-10-04 16:40:45 -04:00
priv_validator.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
priv_validator_test.go update for sdk2 libs. need to fix kv test 2018-02-03 03:35:02 -05:00
proposal.go Add timestamp to vote canonical encoding 2017-12-12 12:59:51 +01:00
proposal_test.go Add more tests for Proposal/Vote serialization 2017-12-12 12:59:51 +01:00
protobuf.go update for sdk2 libs. need to fix kv test 2018-02-03 03:35:02 -05:00
results.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
results_test.go Add /block_results?height=H as rpc endpoint 2017-12-26 19:24:25 -05:00
services.go call FlushSync before calling CommitSync 2018-01-23 16:56:14 +04:00
signable.go update types 2018-02-03 03:23:10 -05:00
test_util.go forgot file 2017-12-21 16:49:47 -05:00
tx.go replace data.Bytes with cmn.HexBytes 2018-02-03 03:47:01 -05:00
tx_test.go all: no more anonymous imports 2017-10-04 16:40:45 -04:00
validator.go update for sdk2 libs. need to fix kv test 2018-02-03 03:35:02 -05:00
validator_set.go update types 2018-02-03 03:23:10 -05:00
validator_set_test.go add safe*Clip funcs 2017-12-26 14:13:12 -06:00
vote.go update for sdk2 libs. need to fix kv test 2018-02-03 03:35:02 -05:00
vote_set.go improve vague error msg, closes #1158 2018-01-31 17:44:19 +00:00
vote_set_test.go separate block vs state based validation 2017-12-21 16:49:47 -05:00
vote_test.go types: Add test for IsVoteTypeValid 2017-12-21 18:13:31 +01:00