Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/compiler/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,12 +1266,31 @@ function statisticValue(s: Statistic) {
case StatisticType.time:
return (s.value / 1000).toFixed(2) + "s";
case StatisticType.memory:
return Math.round(s.value / 1000) + "K";
return formatMemory(s.value);
default:
Debug.assertNever(s.type);
}
}

function formatMemory(bytes: number) {
// bytes -> choose KB/MB/GB with a human friendly format
const KB = 1024;
const MB = KB * 1024;
const GB = MB * 1024;
const numberOfDecimalPlaces = 1;

if (bytes >= GB) {
return (bytes / GB).toFixed(numberOfDecimalPlaces) + " GB";
}

if (bytes >= MB) {
return (bytes / MB).toFixed(numberOfDecimalPlaces) + " MB";
}

const kilobytesUsed = Math.round(bytes / KB);
return kilobytesUsed + " KB";
}

Comment on lines +1275 to +1293
Copy link
Preview

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

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

The function handles negative input values incorrectly. Negative bytes would be compared against positive thresholds and fall through to the KB case, potentially producing misleading output like '-5 KB'. Consider adding input validation or handling negative values explicitly.

Suggested change
function formatMemory(bytes: number) {
// bytes -> choose KB/MB/GB with a human friendly format
const KB = 1024;
const MB = KB * 1024;
const GB = MB * 1024;
const numberOfDecimalPlaces = 1;
if (bytes >= GB) {
return (bytes / GB).toFixed(numberOfDecimalPlaces) + " GB";
}
if (bytes >= MB) {
return (bytes / MB).toFixed(numberOfDecimalPlaces) + " MB";
}
const kilobytesUsed = Math.round(bytes / KB);
return kilobytesUsed + " KB";
}
function formatMemory(bytes: number) {
// bytes -> choose KB/MB/GB with a human friendly format
if (bytes < 0) {
return "N/A";
}
const KB = 1024;
const MB = KB * 1024;
const GB = MB * 1024;
const numberOfDecimalPlaces = 1;
if (bytes >= GB) {
return (bytes / GB).toFixed(numberOfDecimalPlaces) + " GB";
}
if (bytes >= MB) {
return (bytes / MB).toFixed(numberOfDecimalPlaces) + " MB";
}
const kilobytesUsed = Math.round(bytes / KB);
return kilobytesUsed + " KB";
}

Copilot uses AI. Check for mistakes.

function writeConfigFile(
sys: System,
reportDiagnostic: DiagnosticReporter,
Expand Down
Loading