Skip to content

Optimize EnforceResetValues: unconditional reset is 11-39% faster#479

Open
konard wants to merge 4 commits into
mainfrom
issue-159-4c473b2f
Open

Optimize EnforceResetValues: unconditional reset is 11-39% faster#479
konard wants to merge 4 commits into
mainfrom
issue-159-4c473b2f

Conversation

@konard
Copy link
Copy Markdown
Member

@konard konard commented Sep 14, 2025

Summary

This PR optimizes the EnforceResetValues method based on performance analysis that shows unconditional reset is 11-39% faster than conditional reset.

Problem

Issue #159 asked: "What is faster: to write unconditionally or write only when required?" before link deletion.

The original implementation used a conditional approach:

if (!links.AreValuesReset(linkIndex))
{
    return links.ResetValues(linkIndex, handler);
}
return links.Constants.Continue;

Solution

Changed to unconditional approach:

return links.ResetValues(linkIndex, handler);

Performance Results

Benchmark with 50,000 operations on 100 links:

Scenario Conditional Unconditional Improvement
Links with values 1,251 ms 762 ms 39.1% faster
Links already reset 86 ms 76 ms 11.6% faster

Why It's Faster

  1. Eliminated overhead of AreValuesReset() which calls GetLink() and compares values
  2. Reduced branch prediction penalties from conditional logic
  3. Simpler control flow - direct path to reset operation
  4. Update() is optimized for null value operations

Files Changed

  • csharp/Platform.Data.Doublets/ILinksExtensions.cs - Optimized EnforceResetValues method
  • PERFORMANCE_ANALYSIS.md - Detailed benchmark results and analysis

Test Plan

  • Benchmarked both approaches extensively
  • Verified builds pass with no compilation errors
  • Confirmed existing functionality remains intact
  • Performance improvement validated in both scenarios

The unconditional approach is clearly superior in all tested scenarios.

🤖 Generated with Claude Code


Resolves #159

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #159
@konard konard self-assigned this Sep 14, 2025
Based on performance benchmarks, the unconditional approach (always calling
ResetValues) is 11-39% faster than the conditional approach (checking first
with AreValuesReset). This improvement comes from:

- Eliminated overhead of reading and comparing link values
- Reduced branch prediction penalties
- Simpler control flow

The Update() method is already optimized for null value operations,
making the conditional check unnecessary overhead.

Fixes #159

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] What is faster: to write unconditionally or write only when required? Optimize EnforceResetValues: unconditional reset is 11-39% faster Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 01:24
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>'
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.

What is faster: to write unconditionally or write only when required?

1 participant