1.1.0: A big improvement on GC #81
Tao-VanJS
announced in
Announcements
Replies: 2 comments
-
Thank you TAO |
Beta Was this translation helpful? Give feedback.
0 replies
-
There is no change in the implementation of Version |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi fellow VanJSers,
I'm happy to announce the release of VanJS
1.1.0
. 🎉🎉🎉The garbage collection mechanism in VanJS was revamped in
1.1.0
. In this overhaul, we improved the GC handling for derived states and side effects registered inside DOM binding functions to avoid some unnecessary constraints while defining derived states and side effects.In particular, prior to VanJS
1.1.0
, the code below is not recommended:This is because whenever the state
renderPre
is toggled, the binding function will be called, and then a new instance of derived statetext
will be created and subscribe to changes its dependencies:prefix
andsuffix
. As stateprefix
is created outside the scope of the binding function, eventually,prefix
will register many derived states ifrenderPre
is toggled many times - for differenttext
instances created inside the binding function whenever it is executed. All of the derivedtext
instances, except for the most recent one, are actually obsolete, as they're no longer part of the document tree.Prior to VanJS
1.1.0
, users are advised to code with the following style to avoid the GC issue:This works well but it introduces the extra mental overhead for writing memory-leak-free code.
In VanJS
1.1.0
, both pieces of code are correct. This is because we're making derived states and side effects registered inside DOM binding functions bound to the lifecycles of DOM nodes that the binding functions return. In other words, if a binding functionf
returns a DOM nodedom
, all the derived states and side effects registered while executingf
will be garbage collected whendom
is disconnected from the document tree. With this release,van.derive
can be used much more freely to enable more advanced state derivations and bindings.With this improvement, the bundle size increases slightly, gzipped bundle remains at
0.9kB
(958 bytes
from928 bytes
), while minified bundle increases to1.7kB
(1702 bytes
from1630 bytes
) - still being the smallest reactive UI framework in the world.❤️ Hope you can enjoy!
Beta Was this translation helpful? Give feedback.
All reactions