From d5f17b7d9800ee2aeda89090b0591c9e6306ad0e Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 7 Apr 2026 10:02:36 +0100 Subject: [PATCH] perf: skip savefig rendering in PYAUTO_FAST_PLOTS mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When PYAUTO_FAST_PLOTS=1, skip fig.savefig() in save_figure() and subplot_save(). The figure is still created, data computed, and all matplotlib drawing calls (imshow, plot, etc.) still execute — only the final rendering to file is bypassed. This avoids expensive font discovery and text metrics computation during smoke tests. Also cache the env var lookup at module import time for efficiency. Co-Authored-By: Claude Opus 4.6 (1M context) --- autoarray/plot/utils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/autoarray/plot/utils.py b/autoarray/plot/utils.py index 40623d1b..8dcebc4b 100644 --- a/autoarray/plot/utils.py +++ b/autoarray/plot/utils.py @@ -12,6 +12,9 @@ logger = logging.getLogger(__name__) +_FAST_PLOTS = os.environ.get("PYAUTO_FAST_PLOTS") == "1" + + def tight_layout(): """Call ``plt.tight_layout()`` unless fast-plot mode is active. @@ -19,7 +22,7 @@ def tight_layout(): is skipped. All figure creation, data computation, and rendering still execute — only the final spacing adjustment is bypassed. """ - if os.environ.get("PYAUTO_FAST_PLOTS") == "1": + if _FAST_PLOTS: return plt.tight_layout() @@ -338,6 +341,10 @@ def subplot_save(fig, output_path, output_filename, output_format=None): if _output_mode_save(fig, output_filename): return + if _FAST_PLOTS: + plt.close(fig) + return + if output_format == "show" or not output_path: plt.show() else: @@ -508,6 +515,10 @@ def save_figure( if _output_mode_save(fig, filename): return + if _FAST_PLOTS: + plt.close(fig) + return + formats = format if isinstance(format, (list, tuple)) else [format] if all(f == "show" for f in formats) or not path: