This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-12
Channels
- # bangalore-clj (1)
- # beginners (10)
- # boot (5)
- # cljs-dev (47)
- # cljsrn (19)
- # clojure (57)
- # clojure-russia (63)
- # clojure-spec (26)
- # clojure-uk (7)
- # clojurescript (104)
- # cursive (26)
- # data-science (2)
- # datomic (1)
- # dirac (1)
- # hoplon (11)
- # juxt (23)
- # off-topic (16)
- # om (6)
- # onyx (3)
- # parinfer (2)
- # protorepl (2)
- # re-frame (1)
- # ring-swagger (1)
- # untangled (2)
Is there a compilation of approximate code sizes (minified,compiled, gzip'ed) of various cljs libraries? Like core.async, datascript, reagent etc.
@rauh there is no such thing, since it all depends on how much of those things you are using
I think it'd be helpful to have a rough idea in general... Is it 2kb or 50kb, helps a lot to make a decision
so the lib itself does not carry a lot of code, yet the macros may produces huge amounts of code in your js files
Yeah datascript doesn't get DCE very well. Lot's of datastructures and most of the functions are ^:export
ed
as I said it is impossible to give an estimate like that since it will vary greatly depending on each project
I have to disagree that it's impossible. To get a general idea, we can just call the most common functions and then see how much code it added
but if you use both you do not get (datascript + clojure.string) + (core.async + clojure.string)
Well we could get smart about this and look at goog.deps.cljs
(or so?) and see what's coming in (relatively)
I'd probably argue that the differences vary much more because of the compression algorithms getting more efficient the larger the file
as code generated by (go (doseq [x some-seq] some very nested code))
can get extremely large
Yeah but that's something the developer should watch out for by doing an occasional macroexpand
but given the experiences I had over the years, you cannot quite make general assumptions here
But the measures we'd get (using minimal examples) would be an upper bound (if calling most common API functions) so that'd be useful for many people IMO
yeah but again, the measures might be way off due to the keeping/removal of namespaces that a lib uses
If the upper bound says "100kb gzip difference" then it's not useful, but if it says 10kb it's already very useful
I think the only way to get this information is to constantly monitor file sizes of your build, then when you notice big changes you should investigate what caused them. Was thinking to make a boot task that tracks filesizes in git metadata (so it's associated with revs) but didn't do anything in that direction yet
@martinklepsch That's actually what I've been doing for a few months. There is a :watch-fn
that gets called each time a build is done. I then pipe it to nginx and get the brotli+gzip sizes of the builds and (spit..)
-append it in a file to keep a history of file sizes
I think that's the best you can do really (besides extending that basic approach with graphs etc). Because Closure removes code on a per-function basis it's impossible to give modules a fixed size
the only thing that does make sense is - "is this library broken for DCE to work correctly?"
once your dependency graph gets significantly deep such information is even less useful
The equivalent JS is:
var blobStream = require(‘blob-stream’);
var stream = doc.pipe(blobStream());
@cfleming you need to add it as a foreign library
@anmonteiro Thanks!
@anmonteiro So if it’s been bundled to bundle.js, I would do something like:
{:foreign-libs
[{:file “bundle.js"
:file-min “bundle.min.js"
:provides [”blobStream"]}]
:externs [”bundle_externs.js"]}
@cfleming that's it. note, however, that :file
is a filesystem path, not a classpath path
in your ClojureScript namespace, you (:require [blobStream])
but that's just an artificial namespace
you still need to get at the JS objects with js/ObjectThatTheBundleExports
right
they're just prepended to the output
Hey new to Clojurescript. Here's some slightly surprising behavior when running code with advanced optimizations vs. not: ;; behavior when :optimizations :none (def inst #js {:foo "bar"}) (println (.-foo inst)) ;; => "bar" (println (aget inst "foo")) ;; => "bar" ;; behavior when :optimizations :advanced (def inst #js {:foo "bar"}) (println (.-foo inst)) ;; => nil (println (aget inst "foo")) ;; => "bar" I understand that this is b/c Google Closure renames symbols. So, I get it, this code is "incorrect". But why? Is the rule/contract that you should never use property access (.-foo inst) for dynamic Javascript properties? What's a better way to explain/understand this...?
@atdixon you can use property access if you have externs for that stuff
also goog.object/get
is preferred over aget
, which is meant for array access
@atdixon your conclusion is corrrect - and @anmonteiro suggestion is the way to go
@anmonteiro @dnolen perfect - thank you!
@anmonteiro I can’t get this to work, I must be doing something daft. Here’s what I have - I’ve browserified the packages into bundle.js following the instructions here: https://github.com/whamtet/cljs-pdfkit#setup. bundle.js is in the root of my resources, and I believe it’s being loaded since it complained when it was in the wrong location.
if you're using foreign-libs
you don't need to add a script tag
but that alone might not solve your problem
It looks to me like that library assumes I’ve put everything in a script tag, since for the PDF functionality he doesn’t seem to be using foreign libs.
Actually, he has another example which does have source available - I’ll check that out.
@cfleming I think foreign libs should be the same as a script tag
the ClojureScript compiler will order the dependencies such that your bundle comes before the code which requires it
oh, now that I think about it, if the library needs some (foreign lib) dependency to be there but it doesn't require it, there might be problems 🙂
I think he’s browserified the whole lot, his lib requires the PDF stuff but I can’t see any evidence of him using foreign libs.
@anmonteiro Got it, thanks - he’s using (js/require “blob-stream”)
, not foreign libs
heh OK. does the browser support js/require
?
I suppose it's there just because of the browserified bundle