retrogradeorbit / bootleg

Simple template processing command line tool to help build static websites
Eclipse Public License 2.0
254 stars 12 forks source link

Startup performance suggestions #65

Closed borkdude closed 4 years ago

borkdude commented 4 years ago

It currenly takes around 120ms on my Macbook Pro 2019 to load-pod bootleg. Which is pretty good, but maybe there are some ways to improve on it.

(ns mybbscript
  (:require [babashka.pods :as pods]))

(println "loading pod")
(time (pods/load-pod "bootleg")) ;;=> 120ms
(require '[pod.retrogradeorbit.bootleg.enlive :as enlive])

(enlive/at "<p>{{here comes foo}}</p>" [:p]
           (enlive/content "foo")) ;;=> 16ms

These are some possible optimizations:

The above two strategies only seemed to help a little bit.

Maybe we could defer loading of pod namespace code to the require of that namespace. This would work for sci, but not for Clojure. Maybe that's an OK trade-off to make, since Clojure startup is usually around 1.5 or more anyway?

borkdude commented 4 years ago

Some more ideas here: https://github.com/babashka/babashka.pods/issues/14

borkdude commented 4 years ago

Since it's not clear if any of these ideas really significantly speed up things, I'll close this for now, but at least we have it documented somewhere.

retrogradeorbit commented 4 years ago

Thanks for going through all this experimentation

borkdude commented 4 years ago

Yes, updated in babashka/babashka.pods#14. It turns out there are significant gains to be made if we split things up per namespace on demand. It's just that with the example I was initially using, it still used the client side heavy namespaces, that's why I didn't see much difference there, since that's where the most time went. When only using markdown for example, things are much faster when splitting things up per namespace.

borkdude commented 4 years ago

I have implemented a new pod operation to optimize startup time when only some namespaces are used. PR coming.

retrogradeorbit commented 4 years ago

load time on linux slashed from 122 msecs to 18 msecs! Thanks heaps! :partying_face: