Skip to content

Commit

Permalink
perf(event bus): Remove expensive Logger debug call in PublishEventTx…
Browse files Browse the repository at this point in the history
… (backport cometbft#2911) (cometbft#2937) (#38)

Component of cometbft#2869

This on its own is an expected 1% speedup to blocksync on osmosis
mainnet right now.

I originally considered keeping the log lines but with only creating the
logger cost if there is an error, but these are debug logs I've never
seen. I think its better to just remove these debug logs directly,
rather than worry about maintaining them. These aren't even that
concerning scenarios I feel like, as more of the stack moves away from
these.

---

#### PR checklist

- [x] Tests written/updated - Covered by existing tests
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [X] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [X] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request cometbft#2911 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Andy Nogueira <me@andynogueira.dev>
(cherry picked from commit a9991fd)
  • Loading branch information
czarcas7ic authored and mergify[bot] committed May 2, 2024
1 parent b59eaa6 commit 596055c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[event-bus]` Remove the debug logs in PublishEventTx, which were noticed production slowdowns.
([\#2911](https://github.com/cometbft/cometbft/pull/2911))
10 changes: 4 additions & 6 deletions types/event_bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ func (b *EventBus) Publish(eventType string, eventData TMEventData) error {
// map of stringified events where each key is composed of the event
// type and each of the event's attributes keys in the form of
// "{event.Type}.{attribute.Key}" and the value is each attribute's value.
func (b *EventBus) validateAndStringifyEvents(events []types.Event, logger log.Logger) map[string][]string {
func (*EventBus) validateAndStringifyEvents(events []types.Event) map[string][]string {
result := make(map[string][]string)
for _, event := range events {
if len(event.Type) == 0 {
logger.Debug("Got an event with an empty type (skipping)", "event", event)
continue
}

for _, attr := range event.Attributes {
if len(attr.Key) == 0 {
logger.Debug("Got an event attribute with an empty key(skipping)", "event", event)
continue
}

Expand All @@ -136,7 +134,7 @@ func (b *EventBus) PublishEventNewBlock(data EventDataNewBlock) error {
ctx := context.Background()

resultEvents := append(data.ResultBeginBlock.Events, data.ResultEndBlock.Events...)
events := b.validateAndStringifyEvents(resultEvents, b.Logger.With("block", data.Block.StringShort()))
events := b.validateAndStringifyEvents(resultEvents)

// add predefined new block event
events[EventTypeKey] = append(events[EventTypeKey], EventNewBlock)
Expand All @@ -150,7 +148,7 @@ func (b *EventBus) PublishEventNewBlockHeader(data EventDataNewBlockHeader) erro

resultTags := append(data.ResultBeginBlock.Events, data.ResultEndBlock.Events...)
// TODO: Create StringShort method for Header and use it in logger.
events := b.validateAndStringifyEvents(resultTags, b.Logger.With("header", data.Header))
events := b.validateAndStringifyEvents(resultTags)

// add predefined new block header event
events[EventTypeKey] = append(events[EventTypeKey], EventNewBlockHeader)
Expand All @@ -177,7 +175,7 @@ func (b *EventBus) PublishEventTx(data EventDataTx) error {
// no explicit deadline for publishing events
ctx := context.Background()

events := b.validateAndStringifyEvents(data.Result.Events, b.Logger.With("tx", data.Tx))
events := b.validateAndStringifyEvents(data.Result.Events)

// add predefined compositeKeys
events[EventTypeKey] = append(events[EventTypeKey], EventTx)
Expand Down

0 comments on commit 596055c

Please sign in to comment.