optimizely / optimizely/csharp-sdk
[ENHANCEMENT] Logging eagerly serializes each condition on every feature flag evaluation
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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