Skip to content

SDK-466 Cache DateFormatter and skip formatting for filtered log levels#1064

Open
sumeruchat wants to merge 1 commit into
masterfrom
fix/SDK-466-IterableLogUtil-formatDate-caching
Open

SDK-466 Cache DateFormatter and skip formatting for filtered log levels#1064
sumeruchat wants to merge 1 commit into
masterfrom
fix/SDK-466-IterableLogUtil-formatDate-caching

Conversation

@sumeruchat
Copy link
Copy Markdown
Contributor

@sumeruchat sumeruchat commented May 13, 2026

Summary

  • Cache IterableLogUtil's DateFormatter as a private static let so it is created once instead of on every log call (fixes the 2.4–3.2s main-thread hang reported by Wolt via Sentry during foreground transitions).
  • Add an optional shouldLog(level:) -> Bool to IterableLogDelegate (default true when unimplemented) and short-circuit IterableLogUtil.log() before formatLogMessage() when the delegate says no — so apps with DefaultLogDelegate(minLogLevel: .error) no longer pay format cost for filtered ITBInfo()/ITBDebug() calls.
  • DefaultLogDelegate routes its minLogLevel filter through shouldLog; NoneLogDelegate returns false for every level (bonus perf win).

Ticket: SDK-466

Test plan

  • ./agent_build.sh passes
  • ./agent_test.sh passes (unit, notification-extension, and offline-events bundles all 0 failures)
  • New LoggingTests cover the short-circuit: SpyDateProvider confirms currentDate is never accessed when DefaultLogDelegate filters the level out, and never accessed at all under NoneLogDelegate
  • Reviewer: sanity-check the new Obj-C selector name shouldLog: on IterableLogDelegate — low risk (Iterable-owned protocol, matches existing log:message: convention) but worth eyeballing

🤖 Generated with Claude Code

Eliminates 2.4-3.2s main-thread hangs (reported by Wolt via Sentry) caused
by IterableLogUtil.formatDate() allocating a DateFormatter on every call
and formatLogMessage() running before the delegate's log-level filter.

- Cache DateFormatter as a private static let
- Add optional shouldLog(level:) to IterableLogDelegate (default true)
- Short-circuit IterableLogUtil.log() before formatLogMessage() when
  shouldLog returns false
- DefaultLogDelegate routes its minLogLevel filter through shouldLog;
  NoneLogDelegate returns false for every level
- New LoggingTests verify filtered levels never hit the date provider

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.13%. Comparing base (e901170) to head (2878e9c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1064      +/-   ##
==========================================
+ Coverage   71.11%   71.13%   +0.01%     
==========================================
  Files         112      112              
  Lines        9328     9335       +7     
==========================================
+ Hits         6634     6640       +6     
- Misses       2694     2695       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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