Closed trusktr closed 4 years ago
I'm optimistic that the decorators proposal will resolve these concerns.
How many years from now? EDIT: It's more of a statement than a question: of course it is hard to tell, but for some significant amount of time there will be turmoil in the code people write. The existence of MobX's version 6 bump is literally caused by this proposal. It is not ideal to force well-known libraries to undergo such changes.
Class fields [[Define]] semantics causes libraries to take routes of less performance in order to mitigate the overriding non-inheriting nature of class fields.
For example, this is old MobX code with [[Set]] semantics:
This causes the decoration logic to run three times, once per class.
With legacy decorators (and [[Set]] semantics), that looks like this:
Because of the new [[Define]] semantics breaking things, here's what the new MobX 6 will look like (discusson issue):
where
makeObservable
must now be called on every instance of the classes, in every constructor so that it can define the observable property descriptors after the class fields [[Define]] happens.For one instance of
Baz
, themakeObservable
function has to be called three times! And for each call, it performs a (possibly short-circuited) prototype iteration.This is obviously considerably more expensive than if we simply had [[Set]] semantics and could therefore simply apply the features at class-definition time.
Here's the same as the previous example, but using decorators (legacy or newer ones):
It is less verbose and more DRY, but still suffers from runtime overhead beyond class-definition time.
In the old system, 1000 objects of type
Baz
meant only 3 calls fodecorate
. But now, 1000Baz
objects means 3000 calls tomakeObservable
.Who knows when the new decorators will come out (which would allow fixes), but the current landscape is in bad shape now, thanks to [[Define]] semantics.