Skip to content

Conversation

hamirmahal
Copy link

Closes #62374

@Copilot Copilot AI review requested due to automatic review settings September 1, 2025 22:27
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Sep 1, 2025
Copilot

This comment was marked as outdated.

@hamirmahal hamirmahal force-pushed the feat/formatting-for-memory-usage-improvement branch from 661bb51 to 91f725c Compare September 1, 2025 23:07
@hamirmahal hamirmahal requested a review from Copilot September 1, 2025 23:34
Copilot

This comment was marked as outdated.

@hamirmahal hamirmahal force-pushed the feat/formatting-for-memory-usage-improvement branch from 91f725c to 29bb880 Compare September 1, 2025 23:54
@hamirmahal hamirmahal requested a review from Copilot September 1, 2025 23:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the formatting of memory usage statistics in the TypeScript compiler by replacing simple KB formatting with a more human-friendly format that automatically selects appropriate units (KB, MB, GB) based on the memory size.

  • Extracts memory formatting logic into a dedicated formatMemory function
  • Implements dynamic unit selection (KB/MB/GB) with appropriate decimal precision
  • Uses binary units (1024-based) for more accurate memory representation

Comment on lines +1275 to +1293
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";
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

More human readable Memory used output when running tsc
1 participant