Skip to content

Improving actor write performance by skipping runtime "exists" checks on state writes - #1914

Merged
WhitWaldo merged 3 commits into
masterfrom
cache-perf-update
Sep 24, 2026
Merged

WhitWaldo merged 3 commits into
masterfrom
cache-perf-update

Conversation

@WhitWaldo

Copy link
Copy Markdown
Contributor

Description

Setting a value for a key always sets it as an update (effectively an upsert) in the actor state. This means that when a delete happens, the delete is always sent to the runtime even if the key has never existed there (e.g. added to state and then removed before the actor turn completes). In all other respects, caching operates the same but without the check to see if the key already exists in the runtime when setting the value.

I added ample tests to validate that this does not negatively impact the current implementation and expectations.

Great find @olitomlinson !

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #1910

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

… upsert) in the actor state. This means that when a delete happens, the delete is always sent to the runtime even if the key has never existed there (e.g. added to state and then removed before the actor turn completes). In all other respects, caching operates the same but without the check to see if the key already exists in the runtime when setting the value.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@WhitWaldo WhitWaldo added this to the v1.18.x - SDK Patches milestone Sep 24, 2026
@WhitWaldo WhitWaldo self-assigned this Sep 24, 2026
@WhitWaldo
WhitWaldo requested review from a team as code owners September 24, 2026 11:38
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.25%. Comparing base (88aaeef) to head (50f9ed5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1914      +/-   ##
==========================================
+ Coverage   64.19%   64.25%   +0.05%     
==========================================
  Files         358      358              
  Lines       10508    10506       -2     
  Branches     1258     1256       -2     
==========================================
+ Hits         6746     6751       +5     
+ Misses       3426     3422       -4     
+ Partials      336      333       -3     
Flag Coverage Δ
net10.0 64.22% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@WhitWaldo
WhitWaldo merged commit fb365b6 into master Sep 24, 2026
596 of 597 checks passed
@WhitWaldo
WhitWaldo deleted the cache-perf-update branch September 24, 2026 14:51
CasperGN added a commit to CasperGN/python-sdk that referenced this pull request Sep 25, 2026
set_state and set_state_ttl read the state store for a key that was not in
the tracker only to choose between add and update, but the state provider
saves both as the same upsert. The key is now recorded as an update without
that read.

Update rather than add is deliberate: the key may already exist in the
store, so a remove later in the same turn has to send a delete instead of
dropping the pending entry. Deleting a key that turns out not to exist is
harmless; skipping the delete of one that does is not.

Keys the manager knows are absent keep the add kind, so add-then-remove
still sends nothing: try_add_state still reads the store and fails when the
key exists, and a cached "not found" entry still turns into an add.
try_remove_state still reads the store to report whether anything was
removed. A reentrant save refreshes the default tracker the same way
whatever kind the saved change had.

Ports dapr/dotnet-sdk#1914.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discussion: SetStateAsync's existence check costs a round trip on every new key, to optimize a case that may be rare

1 participant