Skip to content

[ENHANCEMENT] Logging eagerly serializes each condition on every feature flag evaluation #422

Description

@JohanPetersson

Description

BaseCondition.ToString() serializes on every log-message construction (BaseCondition.cs):

public override string ToString() => JsonConvert.SerializeObject(this, Formatting.None);

It's used inside interpolated strings like $@"Audience condition {this} evaluated to UNKNOWN...", which C# evaluates eagerly before logger.Log(LogLevel.DEBUG, ...) is called. So even with logging disabled, you pay a JsonConvert.SerializeObject per condition on many paths (Evaluate, ExactEvaluator, NumberEvaluator, SubstringEvaluator, ...). This is a real hot-path cost.

Consider gating the log calls behind a level check so the interpolation doesn't run, or cache the serialized condition.

Benefits

Less allocations and resource utilization and feature flags can be used in hot paths.

Detail

No response

Examples

No response

Risks/Downsides

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions