Skip to content

[python] helpers: import matplotlib only in the plotting functions - #193

Merged
antonio-leblanc merged 1 commit into
forefireAPI:devfrom
yanissrairi:perf/lazy-matplotlib
Oct 5, 2026
Merged

antonio-leblanc merged 1 commit into
forefireAPI:devfrom
yanissrairi:perf/lazy-matplotlib

Conversation

@yanissrairi

Copy link
Copy Markdown
Contributor

pyforefire/__init__.py star-imports helpers, which imported matplotlib at module level, so every import pyforefire loaded it even when nothing is plotted. The imports now live in the two functions that use them, printToPathe and plot_simulation.

Fresh interpreter, median of 30 runs (Python 3.14, matplotlib 3.11):

  • import pyforefire: 0.191 s -> 0.039 s
  • RSS after import: 80 MB -> 41 MB

This matters when running many short simulations in separate processes.

The helper functions return the same outputs as before, and percolation.py and idealizedwind.py in tests/python produce identical files with a fixed seed. One side effect: plt, cm, mpath, mpatches and ListedColormap are no longer re-exported by pyforefire through the star import. Nothing in this repository relies on that.

@yanissrairi
yanissrairi force-pushed the perf/lazy-matplotlib branch 2 times, most recently from 7098209 to f45d70b Compare October 5, 2026 12:11
@yanissrairi
yanissrairi changed the base branch from master to dev October 5, 2026 12:11
import pyforefire was loading matplotlib even when nothing is plotted.
@yanissrairi
yanissrairi force-pushed the perf/lazy-matplotlib branch from f45d70b to 0765090 Compare October 5, 2026 12:14
@filippi

filippi commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

thanks @yanissrairi
@HugoFara doues this collides with the new python interface with runners ? i beleive not, but cannot check yet if that is implemented in dev.

@HugoFara

HugoFara commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

@filippi not a problem on my side. I don't have PRs open to dev now, so there won't be conflicts. Good work @yanissrairi !

@antonio-leblanc antonio-leblanc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

team aproved

@antonio-leblanc
antonio-leblanc merged commit 31a642d into forefireAPI:dev Oct 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants