Skip to content

Commit

Permalink
Change readonly instance props of DurableObjectState to lazy-writable.
Browse files Browse the repository at this point in the history
This is really two changes:

1. Make these lazy properties. This is a strict win since the properties cannot change value during the lifetime of the object, so there's no reason to call into C++ on every access. This might even be a non-negligible performance gain for people who use `ctx.storage` a lot without memoizing it.

2. Make them writable. There's no real reason to prevent people from overwriting these if they really want to. Moreover, introducing `container` as a read-only property could arguably break someone who is, for whatever reason, monkey-patching this property in today.
  • Loading branch information
kentonv committed Jan 22, 2025
1 parent b7299bd commit 8abaf07
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/workerd/api/actor-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ class DurableObjectState: public jsg::Object {

JSG_RESOURCE_TYPE(DurableObjectState, CompatibilityFlags::Reader flags) {
JSG_METHOD(waitUntil);
JSG_READONLY_INSTANCE_PROPERTY(id, getId);
JSG_READONLY_INSTANCE_PROPERTY(storage, getStorage);
JSG_READONLY_INSTANCE_PROPERTY(container, getContainer);
JSG_LAZY_INSTANCE_PROPERTY(id, getId);
JSG_LAZY_INSTANCE_PROPERTY(storage, getStorage);
JSG_LAZY_INSTANCE_PROPERTY(container, getContainer);
JSG_METHOD(blockConcurrencyWhile);
JSG_METHOD(acceptWebSocket);
JSG_METHOD(getWebSockets);
Expand Down

0 comments on commit 8abaf07

Please sign in to comment.