Skip to content

Check log level before logging in hot path#969

Open
kvch wants to merge 2 commits into
mainfrom
perf/hot-path-logging-guards
Open

Check log level before logging in hot path#969
kvch wants to merge 2 commits into
mainfrom
perf/hot-path-logging-guards

Conversation

@kvch

@kvch kvch commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

The WAL listener allocated a 3-entry loglib.Fields map without any log-level check could short-circuit it.
This was a waste of allocations if the log level was not debug or trace.

Metric main (baseline) this pr Δ vs main
Time 520.15n 34.88n −93.29%
Bytes/op 376.0 0.0 −100.00%
Allocs/op 5.000 0.000 −100.00%

Type of Change

Please select the relevant option(s):

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

Changes Made

  • Added IsDebugEnabled() to the loglib.Logger interface and to NoopLogger
  • Wrapped the per-event Trace/Debug calls in IsTraceEnabled()/IsDebugEnabled() checks

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

@kvch kvch requested a review from exekias July 7, 2026 16:05
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/pkg/log 0.00% (ø)
github.com/xataio/pgstream/pkg/wal/listener/kafka 66.67% (-2.90%) 👎
github.com/xataio/pgstream/pkg/wal/listener/postgres 95.74% (-2.08%) 👎
github.com/xataio/pgstream/pkg/wal/processor/filter 92.16% (-1.84%) 👎
github.com/xataio/pgstream/pkg/wal/processor/injector 79.28% (-1.45%) 👎
github.com/xataio/pgstream/pkg/wal/processor/search 80.22% (-0.30%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/pkg/log/logger.go 0.00% (ø) 13 (+1) 0 13 (+1)
github.com/xataio/pgstream/pkg/wal/listener/kafka/wal_kafka_reader.go 66.67% (-2.90%) 24 (+1) 16 8 (+1) 👎
github.com/xataio/pgstream/pkg/wal/listener/postgres/wal_pg_listener.go 95.74% (-2.08%) 47 (+1) 45 2 (+1) 👎
github.com/xataio/pgstream/pkg/wal/processor/filter/wal_filter.go 92.16% (-1.84%) 51 (+1) 47 4 (+1) 👎
github.com/xataio/pgstream/pkg/wal/processor/injector/wal_injector.go 79.28% (-1.45%) 111 (+2) 88 23 (+2) 👎
github.com/xataio/pgstream/pkg/wal/processor/search/search_batch_indexer.go 71.25% (-0.90%) 80 (+1) 57 23 (+1) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant