sci icon indicating copy to clipboard operation
sci copied to clipboard

optimize build size by letting users choose core function(s)(ality)

Open borkdude opened this issue 4 years ago • 4 comments

I think the idea that @ikitommi has:

The namespaces.cljc file contains top-level datastructures with all the core namespaces in it. Those should be lifted into a function and then users can do a select-keys or dissoc on those namespaces, and making a top-level value out of that. That should help.

Also, we have an addons.future namespace to optionally include future functionality. That's also a way to get access to opt-in functionality.

borkdude avatar Jun 25 '20 10:06 borkdude

From Slack #sci:

I think there are ... options here.

first: make all the def defns and split them into smaller parts, e.g. clojure-set-bindings, clojure-walk-bindings etc.

  1. have a global def collecting all in sci.core and create a new entrypoint ns, like sci.custom that doesn’t have the def, but an api that requires the bindings as parameter
  2. have a compiler switch (:closure-defines / :jvm-opts) which allow to empty the default registry
  3. macro-time select-keys, might work, tested something like this, coudn’t get it to work

Example of option 2 done In malli.

1 could have api like:

(require '[sci.api])
(require '[sci.namepaces :as n])
(require '[clojure.walk :as walk])

(def sci-eval 
  (sci.api/evaluator 
    {:bindings (merge (n/cloure-core-bindings) 
                      (n/clojure-set-bindings) 
                      {'walk (n/copy-var clojure.walk/walk...)})})

(sci-eval "(int? 1)")
; => true

ikitommi avatar Jun 25 '20 11:06 ikitommi

I think the option to programmatically create the namespaces.cljc file (to limit access to core vars) is an interesting one. What would happen btw if you right now would include sci.impl.namespaces.cljc in your own project and just edited, ripped out the vars you don't need? I guess that would already work as of now

borkdude avatar Jul 01 '20 12:07 borkdude

The sci.api/evaluator could also do #369 optimization behind the scenes.

ikitommi avatar Jul 20 '20 09:07 ikitommi

tested with dropping all var-mappings from namespaces.

Before:

default-namespaces

After:

empty-namespaces

empty is not anyway useful, but I think it shows the limit how small it could go. The useful minimal would be much bigger.

ikitommi avatar Jul 20 '20 10:07 ikitommi