Skip to content

Clarify dev_startup_time w.r.t. already required nss #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Clarify dev_startup_time w.r.t. already required nss
It wasn't clear to me at all that compile only happens when loading a ns for the first time / force reloading it. HereI try to clarify this for the next person.
  • Loading branch information
holyjak authored Dec 29, 2023
commit 8276ecb77286df1a79e040c0d33dae3741e10d39
9 changes: 7 additions & 2 deletions content/guides/dev_startup_time.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ The `compile` function takes a namespace symbol and compiles that namespace and

Subsequently, when any of those compiled namespaces are required, the class file will be loaded, rather than the original `.clj` file. If a source file is updated (and thus newer), it will be loaded instead. Periodically, you will need to re-compile to account for new dependencies or changing code.

One special case is the `user.clj` file loaded automatically by the Clojure runtime, before any other code is loaded. If you are using a `user.clj` in dev, you need to force a reload because it has already been loaded automatically:
NOTE: Compilation happens as a side-effect of loading a namespace, and thus has no effect on already required ones. Use `*compile-files*` with `:reload-all` as suggested below to compile already loaded namespaces.

One special case is the `user.clj` file loaded automatically by the Clojure runtime, before any other code is loaded. (Though this applies equally to compiling any namespace that has already been loaded into the REPL.) If you are using a `user.clj` in dev, you need to force a reload because it has already been loaded automatically:

[source,clojure]
----
(binding [*compile-files* true] (require 'user :reload-all))
(binding [*compile-files* true] ; <1>
(require 'user :reload-all)) ; <2>
----
<1> Tell Clojure to compile any namespace it is loading
<2> Tell Clojure to reload this and all required namespaces

That's it! This technique can substantially reduce your startup time during development, particularly as the number of dependencies you load increases.

Expand Down