From 0c610f706e30cf5273aaac35a9ea2c6b3c99ea1f Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Thu, 19 Nov 2026 10:23:10 +1100 Subject: [PATCH 1/2] Build matplotlib's font cache before the build On a freshly launched runner the first matplotlib import scans the system fonts from a cold disk, which took 10 to 13 s in an instrumented pair of cache.yml builds (1.9 s warm). Past 5 s matplotlib prints "Matplotlib is building the font cache; this may take a moment." into the output of the first notebook that imports it, about_py, so whether that line reaches the page depended on the instance. One step after the environment is complete, in cache.yml, ci.yml and publish.yml, builds the cache first. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL --- .github/workflows/cache.yml | 9 +++++++++ .github/workflows/ci.yml | 9 +++++++++ .github/workflows/publish.yml | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml index 981325bf..8c655c31 100644 --- a/.github/workflows/cache.yml +++ b/.github/workflows/cache.yml @@ -30,6 +30,15 @@ jobs: pip install "jax[cuda13]==0.11.0" pip install numpyro python scripts/test-jax-install.py + - name: Build matplotlib's font cache + shell: bash -l {0} + run: | + # On a freshly launched runner the first matplotlib import scans the + # system fonts from a cold disk, which can take over 5 s, and + # matplotlib then prints "Matplotlib is building the font cache; this + # may take a moment." into the output of the first notebook that + # imports it. Build the cache here, so no page depends on that timing. + python -c "import matplotlib.pyplot" - name: Check nvidia drivers shell: bash -l {0} run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b1dcda3..a7bf72ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,15 @@ jobs: pip install "jax[cuda13]==0.11.0" pip install numpyro python scripts/test-jax-install.py + - name: Build matplotlib's font cache + shell: bash -l {0} + run: | + # On a freshly launched runner the first matplotlib import scans the + # system fonts from a cold disk, which can take over 5 s, and + # matplotlib then prints "Matplotlib is building the font cache; this + # may take a moment." into the output of the first notebook that + # imports it. Build the cache here, so no page depends on that timing. + python -c "import matplotlib.pyplot" - name: Install latex dependencies run: | sudo apt-get -qq update diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e0b35fe1..eb1a6608 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,6 +47,15 @@ jobs: pip install "jax[cuda13]==0.11.0" pip install numpyro python scripts/test-jax-install.py + - name: Build matplotlib's font cache + shell: bash -l {0} + run: | + # On a freshly launched runner the first matplotlib import scans the + # system fonts from a cold disk, which can take over 5 s, and + # matplotlib then prints "Matplotlib is building the font cache; this + # may take a moment." into the output of the first notebook that + # imports it. Build the cache here, so no page depends on that timing. + python -c "import matplotlib.pyplot" - name: Check nvidia drivers shell: bash -l {0} run: | From 757a702f7d883a6b3c7b00109fadaf7dcd8dc191 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Thu, 19 Nov 2026 10:46:25 +1100 Subject: [PATCH 2/2] Build the font cache by importing the font manager alone matplotlib.font_manager builds the cache on import with no backend involved, so the step cannot depend on which backend the runner would choose (Copilot's review on QuantEcon/lecture-python.myst#1134). pyplot would not have failed there: on a Linux runner without a display matplotlib's automatic choice is Agg. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL --- .github/workflows/cache.yml | 5 +++-- .github/workflows/ci.yml | 5 +++-- .github/workflows/publish.yml | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml index 8c655c31..620855e1 100644 --- a/.github/workflows/cache.yml +++ b/.github/workflows/cache.yml @@ -37,8 +37,9 @@ jobs: # system fonts from a cold disk, which can take over 5 s, and # matplotlib then prints "Matplotlib is building the font cache; this # may take a moment." into the output of the first notebook that - # imports it. Build the cache here, so no page depends on that timing. - python -c "import matplotlib.pyplot" + # imports it. Build the cache here, so no page depends on that timing: + # the font manager builds it on import, with no backend involved. + python -c "import matplotlib.font_manager" - name: Check nvidia drivers shell: bash -l {0} run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7bf72ad..6718ff34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,8 +42,9 @@ jobs: # system fonts from a cold disk, which can take over 5 s, and # matplotlib then prints "Matplotlib is building the font cache; this # may take a moment." into the output of the first notebook that - # imports it. Build the cache here, so no page depends on that timing. - python -c "import matplotlib.pyplot" + # imports it. Build the cache here, so no page depends on that timing: + # the font manager builds it on import, with no backend involved. + python -c "import matplotlib.font_manager" - name: Install latex dependencies run: | sudo apt-get -qq update diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eb1a6608..7186c74f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -54,8 +54,9 @@ jobs: # system fonts from a cold disk, which can take over 5 s, and # matplotlib then prints "Matplotlib is building the font cache; this # may take a moment." into the output of the first notebook that - # imports it. Build the cache here, so no page depends on that timing. - python -c "import matplotlib.pyplot" + # imports it. Build the cache here, so no page depends on that timing: + # the font manager builds it on import, with no backend involved. + python -c "import matplotlib.font_manager" - name: Check nvidia drivers shell: bash -l {0} run: |