metabase / metabase/metabase

Stop loading most of the BE while compiling CLJS

Open
#43,459 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

.Backend .Performance
Dominant language
Clojure
Stars
49.3k
Forks
6.8k
Avg merge
1d 13h
Merged PRs (30d)
653

Description

While compiling CLJS, we accidentally end up loading most of the Metabase BE:

- Compiling CLJS means running macros.
- The macros are written in JVM Clojure, and run inside the CLJS compiler.
- So CLJS compilation begins by loading the same code (more or less) in JVM Clojure.
- That accidentally includes a large chunk of Metabase's BE code, including parts that try to start DB connections among much else.

Rearranging some namespaces and requires, and/or making the expensive things a bit lazier, should be able to reduce that startup time greatly. I don't have a good dependency graph, but I got a good picture of which namespaces (transitively) take a long time to load using [this Clojure patch](https://gist.github.com/pesterhazy/7f8af5701b51ccd86f99fc222436e6ea) which logs each namespace's load time. `metabase.util` (and in particular its `metabase.util.jvm` that it re-exports in JVM Clojure) are particularly suspect.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by applying the linked Clojure namespace-load-time logging patch and inspect metabase.util, especially metabase.util.jvm, during CLJS compilation. Trace the namespaces that pull in backend code and database startup; done means CLJS compilation no longer loads most of the BE and startup time is greatly reduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
backend, build-system, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.