Spent some time messing around w/ Proxy - it's gotten a lot, lot faster
it also can be done lazily - so seems like some serious advantages over clj->js
sounds similar to cljs-bean?
has it become a lot faster compared to just objects though?
cljs-bean is useful, but the wrong way
ten years ago or whatever it was 1000X slower, now <10x slower or something
but that isn't the only thing we're measuring
clj->js isn't lazy and generates a lot of garbage
(meaning it just allocates like crazy on the way to producing a JS values)
I've considered doing proper immutability in squint using proxy
as a replacement for clj->js it might work nicely. I wonder if you can also accomplish "expose cljs data structure as JS object" without an explicit call to wrap it in a proxy? that might be messy and would likely cause perf issues for existing callers
I wonder if the js-interop already has done something like this
I did a bunch of research, there's no transparent way in the JS standard - doing anything in CLJS is just too magical
transparent way of doing what?
you need explicit calls to wrap in proxy
👍
exhibit A where this would be nice any JS lib way to deal w/ DOM attributes - having to always clj->js that is meh.
If have this little thing for it now: https://github.com/borkdude/reagami/blob/7e23c82c37726f9e749a28cf94677b5631df589d/src/reagami/core.cljc#L75-L86 Do you think converting in a proxy would result in any perf wins? You have to visit them all anyway so the time building a new JS obj may be just as fast as looking up things via a proxy. Need to measure this.
proxied get w/ carefully written code + caching is faster than convert then read. again that's not factoring memory issues in less trivial programs.
this is JSC, I need to verify Chrome & Firefox, though my impression is Proxy perf is good there too.
I didn't realize that Vue.js was using this as the dependency tracking mechanism since 2020 (?) - so I have a feeling this technique has been taken up elsewhere and JS engines have optimized
I remember @wilkerlucio experimented with Proxy some years ago and wrote his findings here https://blog.wsscode.com/alternative-to-clj-js/
yeah it seems most of those runs are out of date, Proxy doesn't look bad any more, especially as the size grows
the benchmarks run in your browser
I know I just re-ran them all in Safari and Chrome, Proxy wins almost always
and this is probably naive proxy, not super finely tuned like I am considering
makes sense
I always thought Proxy was cool, but 10 years to make it fast sounds about right 🙂
This is very cool!