Skip to content

feat: formatting for Memory used improvement - #62375

Closed
Hamir (hirehamir) wants to merge 1 commit into
microsoft:mainfrom
hirehamir:feat/formatting-for-memory-usage-improvement
Closed

feat: formatting for Memory used improvement#62375
Hamir (hirehamir) wants to merge 1 commit into
microsoft:mainfrom
hirehamir:feat/formatting-for-memory-usage-improvement

Conversation

@hirehamir

Copy link
Copy Markdown

Closes #62374

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

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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";
}

Copilot AI Sep 1, 2025

Copy link

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.
@jakebailey

Copy link
Copy Markdown
Member

The linked issue is closed as not planned; we aren't going to take this.

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Oct 13, 2025
@typescript-bot

Copy link
Copy Markdown
Contributor

The TypeScript team hasn't accepted the linked issue #62374. If you can get it accepted, this PR will have a better chance of being reviewed.

@hirehamir
Hamir (hirehamir) deleted the feat/formatting-for-memory-usage-improvement branch October 13, 2025 17:09
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Apr 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

More human readable Memory used output when running tsc

4 participants