JakeWharton / JakeWharton/timber

Multiple Trees evaluate String templates independently

Open
#644 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
10.8k
Forks
994
Avg merge
17h 16m
Merged PRs (30d)
17

Description

The main reason to continue to use templates instead of Kotlin's interpolation is so that if putting together the `String` is expensive, but logging isn't actually enabled for a particular level/tag, the cost is avoided entirely.

However, if there are multiple `Timber.Tree`s that accept a given log, then a `String` template is actually evaluated separately for each one, so if there was any significance to not creating it sometimes, that's offset by creating it multiple times instead. (Ideally, logging is skipped more often than it is evaluated, particularly in production, but that's not always the case.)

Would it be worth fixing this, perhaps by having `Forest` first identify the first `Tree` that would log the message, then evaluating the message, then logging it to all applicable `Tree`s?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing Forest's dispatch flow and how each Tree determines whether it accepts a log message. Check the existing logging tests before changing behavior. Done means an expensive String template is evaluated at most once when one or more Trees will log, while all applicable Trees still receive the message and skipped logging avoids evaluation.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
performance, tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.