Skip to content

Instantly share code, notes, and snippets.

@rauhs
Last active July 7, 2017 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauhs/ee1609ecb7cbe1bddd57f9469ddd0f48 to your computer and use it in GitHub Desktop.
Save rauhs/ee1609ecb7cbe1bddd57f9469ddd0f48 to your computer and use it in GitHub Desktop.

Currently:

    cljs.core.complement = (function cljs$core$complement(f) {
        return (function() {
            var G__10928 = null;
            var G__10928__0 = //impl
            var G__10928__1 = //impl
            var G__10928__2 = //impl
            var G__10928__3 = (function() {
                var G__10929__delegate = function(x, y, zs) {
                    // variadic implementation
                };
                var G__10929 = function(x, y, var_args) {
                    // dispatcher calling above delegate fn
                };
                G__10929.cljs$lang$maxFixedArity = 2;
                G__10929.cljs$lang$applyTo = // snip
                G__10929.cljs$core$IFn$_invoke$arity$variadic = G__10929__delegate;
                return G__10929;
            })();
            G__10928 = function(x, y, var_args) {
                // Dispatcher fn
                // it'll eventually call:
                return G__10928__3.cljs$core$IFn$_invoke$arity$variadic(x, y, G__10932);
            };
            G__10928.cljs$lang$maxFixedArity = 2;
            /// !!! Copies applyto
            G__10928.cljs$lang$applyTo = G__10928__3.cljs$lang$applyTo;
            G__10928.cljs$core$IFn$_invoke$arity$0 = G__10928__0;
            G__10928.cljs$core$IFn$_invoke$arity$1 = G__10928__1;
            G__10928.cljs$core$IFn$_invoke$arity$2 = G__10928__2;
            // !!! Only copies variadic impl
            G__10928.cljs$core$IFn$_invoke$arity$variadic = G__10928__3.cljs$core$IFn$_invoke$arity$variadic;
            return G__10928;
        })()
    }); 

New:

    cljs.core.complement = (function cljs$core$complement(f) {
        return (function() {
            var G__9681 = null;
            var G__9681__0 = // impl
            var G__9681__1 = // impl
            var G__9681__2 = // impl
            var G__9681__3__impl = // variadic impl
            var G__9681__3$cljs$lang$applyTo = // snip
            var G__9681__3$cljs$core$IFn$_invoke$arity$variadic = G__9681__3__impl;
            G__9681 = function(x, y, var_args) {
              // The fn dispatcher, now using:
              return G__9681__3$cljs$core$IFn$_invoke$arity$variadic(x, y, G__9684);
            };
            G__9681.cljs$lang$maxFixedArity = 2;
            // Copy applyTo:
            G__9681.cljs$lang$applyTo = G__9681__3$cljs$lang$applyTo;
            G__9681.cljs$core$IFn$_invoke$arity$0 = G__9681__0;
            G__9681.cljs$core$IFn$_invoke$arity$1 = G__9681__1;
            G__9681.cljs$core$IFn$_invoke$arity$2 = G__9681__2;
            // Reusing above variadic
            G__9681.cljs$core$IFn$_invoke$arity$variadic = G__9681__3$cljs$core$IFn$_invoke$arity$variadic;
            return G__9681;
        })()
    }); 

Benefits:

  • Faster compile times?
  • Smaller code
  • Faster code by avoiding IIFE
  • Better optimization by GCC

Benchmarks

    (enable-console-print!)
    (dotimes [_ 2]
      (simple-benchmark []
        (set! js/xxxx (comp inc dec +))
        1000000))

;; NEW: FF: 360ms   Chrome: 1300
;; OLD: FF: 470     Chrome: 1900
@rauhs
Copy link
Author

rauhs commented Jul 7, 2017

New benefit, probably better DCE by Closure Compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment