Skip to content

Conversation

@sodre
Copy link
Member

@sodre sodre commented Jan 26, 2026

Summary

Implemented resource registry pattern to replace expensive Scan operation with atomic GetItem in list_resources_with_defaults(). This resolves issue #233 and significantly improves performance and cost for large deployments.

Changes

  • Added schema key builders for resource registry record (PK=SYSTEM#, SK=#RESOURCES)
  • Implemented atomic SET/DELETE operations using DynamoDB string sets
  • Replaced O(N) Scan with O(1) GetItem operation
  • Updated CLAUDE.md documentation with new access pattern

Performance Impact

  • Before: O(N) RCU consumption (reads all table items, potentially 100K+)
  • After: 1 RCU per call (constant time)
  • Cost reduction: ~99% for large tables with many non-resource items

Test Results

  • ✅ All 904 unit tests pass
  • ✅ Pre-commit hooks pass (ruff, mypy, cfn-lint)
  • ✅ No regressions in existing functionality

Files Modified

  • src/zae_limiter/schema.py - Added resource registry key builders
  • src/zae_limiter/repository.py - Implemented atomic GetItem/SetItem for registry
  • CLAUDE.md - Updated DynamoDB access patterns documentation

Fixes #233

…es_with_defaults()

Replace expensive Scan operation with atomic GetItem on resource registry record.
Reduces RCU consumption from N (where N = total items in table) to 1 RCU.

- Add SK_RESOURCES constant and sk_resources() key builder to schema.py
- Update set_resource_defaults() to atomically ADD resource to registry set
- Update delete_resource_defaults() to atomically DELETE resource from registry set
- Replace list_resources_with_defaults() Scan with single GetItem on SYSTEM#/RESOURCES registry
- Update CLAUDE.md DynamoDB Access Patterns table with resource registry entry

Fixes #233

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.53%. Comparing base (ca3f79e) to head (478c5a5).
⚠️ Report is 5 commits behind head on milestone/0.6.0.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                 Coverage Diff                 @@
##           milestone/0.6.0     #238      +/-   ##
===================================================
+ Coverage            94.52%   94.53%   +0.01%     
===================================================
  Files                   26       26              
  Lines                 3906     3899       -7     
===================================================
- Hits                  3692     3686       -6     
+ Misses                 214      213       -1     
Flag Coverage Δ
e2e 52.50% <44.44%> (+0.19%) ⬆️
integration 63.81% <100.00%> (-0.04%) ⬇️
unit 93.61% <100.00%> (+0.01%) ⬆️

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

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

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: 478c5a5 Previous: 9e4a844 Ratio
tests/benchmark/test_operations.py::TestCascadeOverheadBenchmarks::test_acquire_without_cascade 60.352737738054486 iter/sec (stddev: 0.024126451235096266) 126.2154851237963 iter/sec (stddev: 0.00950221434029026) 2.09
tests/benchmark/test_operations.py::TestConfigLookupBenchmarks::test_acquire_cold_config 42.84766418513174 iter/sec (stddev: 0.043887948133382614) 59.94391109829673 iter/sec (stddev: 0.014295610668191978) 1.40
tests/benchmark/test_operations.py::TestConcurrentThroughputBenchmarks::test_sequential_acquisitions 7.35860369890624 iter/sec (stddev: 0.13937538243426856) 16.996027066502045 iter/sec (stddev: 0.009269329440738942) 2.31

This comment was automatically generated by workflow using github-action-benchmark.

@sodre sodre added performance Performance optimization area/limiter Core rate limiting logic labels Jan 26, 2026
@sodre sodre added this to the v0.6.0 milestone Jan 26, 2026
Clarify that ADD and DELETE operations don't use SET prefix in DynamoDB
UpdateExpression syntax. Changed "atomic SET ADD operation" to "atomic ADD
operation" and "atomic SET DELETE operation" to "atomic DELETE operation".

This is a documentation-only fix with no code logic changes.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@sodre sodre merged commit 4cbe6e2 into milestone/0.6.0 Jan 26, 2026
10 checks passed
@sodre sodre deleted the feat/233-resource-registry branch January 26, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/limiter Core rate limiting logic performance Performance optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants