optimizely / optimizely/csharp-sdk

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

Open
#422 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

acknowledged enhancement
Dominant language
C#
Stars
20
Forks
20
Avg merge
22h 59m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with OptimizelySDK/AudienceConditions/BaseCondition.cs and inspect the logging paths in Evaluate, ExactEvaluator, NumberEvaluator, and SubstringEvaluator. Trace how interpolated messages reach logger.Log when debug logging is disabled, then verify that condition serialization is avoided or reused without changing the logged messages or evaluation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.