philoskim / debux

A trace-based debugging library for Clojure and ClojureScript.
468 stars 19 forks source link

Can't init clojurescript in clojure-only project #3

Closed mishadoff closed 6 years ago

mishadoff commented 6 years ago

I have a plain clojure project (no clojurescript), when I use debux and require core namespace in REPL i get exception

CompilerException java.io.FileNotFoundException: Could not locate cljs/analyzer/api__init.class or cljs/analyzer/api.clj on classpath., compiling:(debux/common/util.cljc)

Probably this caused by init of [cljs.analyzer.api :as ana] which is not in classpath. Is there a way to disable clojurescript and make it work for clojure only?

P.S. Adding clojurescript deps looks like short term fix, but would be good to avoid unnecessary deps

philoskim commented 6 years ago

Thanks for your pointing out this error. This problem will be solved in the next version of debux.

My solution is simple.

The following part of debux/project.clj

:dependencies [[org.clojure/clojure "1.8.0" :scope "provided"]
               [org.clojure/clojurescript "1.9.854" :scope "provided"]]

will be changed to the following.

:dependencies [[org.clojure/clojure "1.8.0"]
               [org.clojure/clojurescript "1.9.854"]]

That is, the default cversion of clojure and clojurescript will be provided by debux, not you. So you don't need to include clojurescript dependency in your project.clj.

mishadoff commented 6 years ago

Wouldn't be better to require clojure script related namespaces with reader macro? So that we don't bring unnecessary deps in classpath?

#?(:cljs (:require [cljs.analyzer.api :as ana]))
philoskim commented 6 years ago

Debux library has over 90% of macro related codes by the nature of this library and I had a lot of trial and error experience on the macro programming.

In my knowledge and practice, your suggestion doesn't work, because the macro expansions in ClojureScript are carried out before compile time by Clojure, not by ClojureScript. So every code executed during macro-expansion time has to be located in #?(:clj ...), not in #?(:cljs ...).

At first, I thought which code should be changed to meet your requirement. After long review, I conclude that the shared codes between Clojure and ClojureScript has to be dupicated too much to meet your requirement and it is not desirable. So I decided to discard code rewriting and change the project.clj as above. It's not clean solution but simple one from a viewpoint of implementation. So I chose it.

If I am wrong, please let me know about it.

philoskim commented 6 years ago

Now debux has a new production version debux-stubs (https://github.com/philoskim/debux#two-libraries) library and the explaination about it is here (https://github.com/philoskim/debux#two-libraries). If you use this library in production, no unnecessary dependencies will be added to the classpath. Thanks a lot for the suggestion!

onetom commented 4 years ago

I've also just looked into this issue, because the load time of debux is quite substantial (~1s on a beefy 8core i9). My suspicion is that it's caused by the requirement to load the cljs analyser.

To get rid of ClojureScript dependency, the cleanest way would be to fork the library and remove any cljs related code. This of course introduces extra maintenance burden, but given how little this library changes lately; it might worth the effort.

What do you think @philoskim ? Am I missing something, or it worth giving it a try to gut cljs from it?

philoskim commented 4 years ago

@onetom

I measured the load time of debux in the Clojure REPL several times like this.

(ns examples.lab)

(time (use 'debux.core))

The results are as follows.

"Elapsed time: 0.400357 msecs"
"Elapsed time: 0.328361 msecs"
"Elapsed time: 0.328984 msecs"
"Elapsed time: 0.35696 msecs"

The CPU of my notebook is the Intel i7-6500U dual cores.

I think that the load time is relatively small, compared to the entire development time. So now I don't consider separating debux into the Clojure and ClojureScript versions.

Sorry to say that.