Skip to content

Commit 40fd2f1

Browse files
authored
memory_report.py: suppress the detailed table if all changes are <0.01MB big (#23212)
1 parent 62ba1e8 commit 40fd2f1

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

scripts/memory_report.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
import subprocess
2626
import sys
2727
import tempfile
28+
from collections.abc import Mapping
2829
from dataclasses import dataclass, field
2930
from pathlib import Path
30-
from typing import Any, Self
31+
from typing import Any, Final, Self
3132

3233
# Known projects with their Git URLs for memory testing.
33-
KNOWN_PROJECTS: dict[str, str] = {
34+
KNOWN_PROJECTS: Final[Mapping[str, str]] = {
3435
"flake8": "https://github.com/PyCQA/flake8",
3536
"sphinx": "https://github.com/sphinx-doc/sphinx",
3637
"prefect": "https://github.com/PrefectHQ/prefect",
@@ -103,7 +104,7 @@ def format_diff(*, old_bytes: int, new_bytes: int) -> str:
103104
if old_bytes == 0:
104105
return f"{sign}{format_bytes(diff)} (new)"
105106

106-
return f"{sign}{diff / old_bytes:.1%} ({format_bytes(abs(diff))})"
107+
return f"{sign}{diff / old_bytes:.2%} ({format_bytes(abs(diff))})"
107108

108109

109110
def format_outcome(*, old_bytes: int, new_bytes: int) -> str:
@@ -114,7 +115,7 @@ def format_outcome(*, old_bytes: int, new_bytes: int) -> str:
114115
elif diff < 0:
115116
return "⬇️"
116117
else:
117-
return "☑️"
118+
return ""
118119

119120

120121
def load_reports_from_directory(directory: Path) -> dict[str, MemoryReport]:
@@ -155,7 +156,7 @@ def diff_items(
155156

156157

157158
# Maximum number of changed items to show per category in the detailed breakdown
158-
MAX_CHANGED_ITEMS = 15
159+
MAX_CHANGED_ITEMS: Final = 15
159160

160161

161162
def render_summary(projects: list[ProjectComparison]) -> str:
@@ -165,8 +166,9 @@ def render_summary(projects: list[ProjectComparison]) -> str:
165166

166167
projects.sort(key=lambda p: p.total_diff_bytes, reverse=True)
167168

168-
any_increased = any(p.total_diff_bytes > 0 for p in projects)
169-
any_decreased = any(p.total_diff_bytes < 0 for p in projects)
169+
# Suppress the memory report if no project had any top-line changes >10KB
170+
any_increased = any(p.total_diff_bytes > 10_000 for p in projects)
171+
any_decreased = any(p.total_diff_bytes < -10_000 for p in projects)
170172
any_changed = any_increased or any_decreased
171173

172174
lines = ["## Memory usage report", ""]
@@ -246,7 +248,7 @@ def render_summary(projects: list[ProjectComparison]) -> str:
246248
]
247249
)
248250
else:
249-
lines.append("Memory usage unchanged :white_check_mark:")
251+
lines.append("Memory usage unchanged ")
250252

251253
return "\n".join(lines)
252254

0 commit comments

Comments
 (0)