Module: RactorRailsShim::StorageStrategy
- Defined in:
- lib/ractor_rails_shim/foundation/storage_strategy.rb
Defined Under Namespace
Constant Summary collapse
- CA_KEY_CACHE_KEY =
Literal key for the per-receiver class_attribute storage-key cache, stored in ractor-local IES (IsolatedExecutionState) so each Ractor carries its own copy (no cross-ractor shareability concern — and class variables are illegal from non-main Ractors).
:"__ractor_rails_shim_ca_key_cache__"
Class Method Summary collapse
-
.ca_key(owner, attr_sym) ⇒ Object
Per-receiver class_attribute storage-key cache.
Class Method Details
.ca_key(owner, attr_sym) ⇒ Object
Per-receiver class_attribute storage-key cache. Maps
(attribute-symbol, receiver-object_id) -> storage-key-symbol so the
hot reader path does NOT re-build a :"..." interpolated key on every
read (which allocated ~2 strings/symbols per read). The key is derived
once per (attribute, class) and memoized in ractor-local IES. After the
first (warm-up) read for a class, all subsequent reads hit the cache
with zero allocation.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ractor_rails_shim/foundation/storage_strategy.rb', line 40 def self.ca_key(owner, attr_sym) oid = (owner.is_a?(Module) ? owner : owner.class).object_id cache = RactorRailsShim.storage[CA_KEY_CACHE_KEY] unless cache cache = {} RactorRailsShim.storage[CA_KEY_CACHE_KEY] = cache end inner = cache[attr_sym] unless inner inner = {} cache[attr_sym] = inner end kkey = inner[oid] unless kkey kkey = :"ractor_rails_shim_class_attr_#{oid}_#{attr_sym}" inner[oid] = kkey end kkey end |