fast icon indicating copy to clipboard operation
fast copied to clipboard

fix: FAST `state()` reactive state core uses slow patterns

Open slightlyoff opened this issue 8 months ago • 0 comments

🐛 Bug Report

The current implementation of State relies on patterns that are extremely likely to end up on the slow path in V8.

For example, there's an early polymorphic string type check, followed by a series of runtime invocations of Object.defineProperty(). Worst of all, there's an implicit and explicit Object.freeze() calls, which will do all sorts of nasty things to the IC caches of any object that is mangled this way.

💁 Possible Solution

Where possible, it would be best to avoid runtime definition of properties via defineProperty and instead use class ctor-time object extensions; i.e., subclassing from some State superclass instead.

As for calls to freeze(), this should be effectively banished to dev-time and never called in the real world unless there's a super compelling reason.

slightlyoff avatar Jun 23 '25 17:06 slightlyoff