1.1 KiB
1.1 KiB
Object indexer extension follow-up
Context
Obj.getAt/Obj.putAtnow support scoped extension indexers for named singletonobjectdeclarations, so patterns likeStorage["name"]can route throughoverride fun Storage.getAt(...)andoverride fun Storage.putAt(...).- Dispatch order is intentionally:
- concrete non-root class members
- scoped extensions
- built-in string-field fallback
Why this order
- Normal class-defined indexers are the common fast path and should not pay extension lookup cost first.
- Checking scoped extensions earlier caused avoidable overhead for regular overridden indexers.
- Routing extension indexers through the generic root
Obj.getAtmember path caused recursion; direct extension dispatch avoids that.
Possible future optimization
- If extension-based indexers show up in hot profiles, add a tiny receiver-shape/member cache at the extension-dispatch points in
Obj.getAt/Obj.putAt. - The cache should stay behind the concrete non-root member fast path.
- A good shape key is likely
(receiver class id/layout version, member name)with the cached extension record/wrapper.