cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
niwinz 2021-06-05T08:20:39.140300Z

Hello, I was looking at the code generated by reify a bit, and I have noticed that in production build it preserves the N conditionals for each namespace segment.

niwinz 2021-06-05T08:21:30.140800Z

I wonder if this can be avoided.

niwinz 2021-06-05T08:26:42.142200Z

I have tried to implement an experimental reify variant that uses different exists? impl, that results in a more simple checking on dev build:

if((typeof app.main.data.viewer.t_app$main$data$viewer57870 !== 'undefined')){
} else {
(app.main.data.viewer.t_app$main$data$viewer57870 = (function (){

niwinz 2021-06-05T08:35:10.142700Z

The question here is, how troublesome can this be? In development build at the end and at the end everything loads in order, and if it does not load in order, other problems will also appear (so checking segments is it possible that it is redundant?) In the production build, access to the generated class variable is done directly, so checking the existence of variables that represent the namespace segments also looks redundant. I'm wrong?

niwinz 2021-06-05T08:44:41.144400Z

I have tried it in a large codebase that uses reify extensively and everything is working as expected (prod and dev builds), but i want to ask here if I'm missing something evident...

thheller 2021-06-05T10:15:44.144700Z

@niwinz https://clojure.atlassian.net/browse/CLJS-3055

thheller 2021-06-05T10:18:10.145100Z

somewhat related https://ask.clojure.org/index.php/8879/cljs-should-macros-support-lifting-vars-to-the-ns-level since with this reify wouldn't need that check at all

thheller 2021-06-05T10:22:11.145500Z

also related https://clojure.atlassian.net/browse/CLJS-3207 😉

niwinz 2021-06-05T10:23:32.145900Z

thanks @thheller

thheller 2021-06-05T10:25:23.147200Z

the reason exists? checks all the nested stuff is because previously it would blow up if namespaces didn't actually exist. so checking app.main.data would fail and break the check if there was no app.main

thheller 2021-06-05T10:26:00.147500Z

not a problem reify will ever have but exists? in general might

niwinz 2021-06-05T10:38:17.148800Z

yeah, this is something what i thought