Skip to content

Commit d5f17b7

Browse files
Jammy2211claude
authored andcommitted
perf: skip savefig rendering in PYAUTO_FAST_PLOTS mode
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) <noreply@anthropic.com>
1 parent 408ceee commit d5f17b7

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

autoarray/plot/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
logger = logging.getLogger(__name__)
1313

1414

15+
_FAST_PLOTS = os.environ.get("PYAUTO_FAST_PLOTS") == "1"
16+
17+
1518
def tight_layout():
1619
"""Call ``plt.tight_layout()`` unless fast-plot mode is active.
1720
1821
When ``PYAUTO_FAST_PLOTS=1`` the expensive layout-optimisation pass
1922
is skipped. All figure creation, data computation, and rendering
2023
still execute — only the final spacing adjustment is bypassed.
2124
"""
22-
if os.environ.get("PYAUTO_FAST_PLOTS") == "1":
25+
if _FAST_PLOTS:
2326
return
2427
plt.tight_layout()
2528

@@ -338,6 +341,10 @@ def subplot_save(fig, output_path, output_filename, output_format=None):
338341
if _output_mode_save(fig, output_filename):
339342
return
340343

344+
if _FAST_PLOTS:
345+
plt.close(fig)
346+
return
347+
341348
if output_format == "show" or not output_path:
342349
plt.show()
343350
else:
@@ -508,6 +515,10 @@ def save_figure(
508515
if _output_mode_save(fig, filename):
509516
return
510517

518+
if _FAST_PLOTS:
519+
plt.close(fig)
520+
return
521+
511522
formats = format if isinstance(format, (list, tuple)) else [format]
512523

513524
if all(f == "show" for f in formats) or not path:

0 commit comments

Comments
 (0)