-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
report: use KiB instead of KB #10870
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this patch too? displayUnit: 'kb'
is the only other thing I think we might want to make a note of to change soon so that if we eventually introduce kB
it's not so confusing.
diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
index 1add4d238..7f8297be4 100644
--- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
+++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
@@ -26,7 +26,7 @@ const MAX_RESOURCE_SIZE_TO_ENCODE = 2000 * 1024;
const JPEG_QUALITY = 0.92;
const WEBP_QUALITY = 0.85;
-const MINIMUM_IMAGE_SIZE = 4096; // savings of <4 KB will be ignored in the audit anyway
+const MINIMUM_IMAGE_SIZE = 4096; // savings of <4 KiB will be ignored in the audit anyway
const IMAGE_REGEX = /^image\/((x|ms|x-ms)-)?(png|bmp|jpeg)$/;
diff --git a/lighthouse-core/lib/i18n/README.md b/lighthouse-core/lib/i18n/README.md
index 8ec3779d9..58e8de4b7 100644
--- a/lighthouse-core/lib/i18n/README.md
+++ b/lighthouse-core/lib/i18n/README.md
@@ -268,12 +268,12 @@ CTC is a name that is distinct and identifies this as the Chrome translation for
This is also the point at which ICU is replaced by values. So this...
```javascript
- message = "Total size was {totalBytes, number, bytes} KB"
+ message = "Total size was {totalBytes, number, bytes} KiB"
sent_values = {totalBytes: 10240}
```
Becomes...
```javascript
- message = "Total size was 10 KB"
+ message = "Total size was 10 KiB"
```
diff --git a/lighthouse-core/report/html/renderer/details-renderer.js b/lighthouse-core/report/html/renderer/details-renderer.js
index 958a5db7d..bd162c87a 100644
--- a/lighthouse-core/report/html/renderer/details-renderer.js
+++ b/lighthouse-core/report/html/renderer/details-renderer.js
@@ -75,6 +75,7 @@ class DetailsRenderer {
*/
_renderBytes(details) {
// TODO: handle displayUnit once we have something other than 'kb'
+ // Note that 'kb' is historical and actually represents KiB.
const value = Util.i18n.formatBytesToKiB(details.value, details.granularity);
const text = this._renderText(value);
text.setAttribute('title', Util.i18n.formatNumber(details.value));
<3 this change. Doc updates: GoogleChrome/web.dev#3070 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM2
/** Used to summarize the total byte size of the page and all its network requests. The `{totalBytes}` placeholder will be replaced with the total byte sizes, shown in kilobytes (e.g. 142 KB) */ | ||
displayValue: 'Total size was {totalBytes, number, bytes}\xa0KB', | ||
/** Used to summarize the total byte size of the page and all its network requests. The `{totalBytes}` placeholder will be replaced with the total byte sizes, shown in kibibytes (e.g. 142 KiB) */ | ||
displayValue: 'Total size was {totalBytes, number, bytes}\xa0KiB', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to say we should really transition these to Intl.NumberFormat
with its new support for localization of numbers+unit, but it only supports kilobyte
, not kibibyte
:(
return this._renderText(value); | ||
const value = Util.i18n.formatBytesToKiB(details.value, details.granularity); | ||
const text = this._renderText(value); | ||
text.setAttribute('title', Util.i18n.formatNumber(details.value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, why do this? You mentioned doing this in the PR description but didn't say why :) I don't have any objection just wondering why it's beneficial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate when tools do this with labels I'm unfamiliar with. If I'm unsure if KiB means 1000 or 1024, a quick hover to see the real value relative to the elided value tells me right away.
also it's nice to just be able to see the real size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it's nice to just be able to see the real size
note it's not always a real size :) (estimated opportunities and sometimes already rounded to various degrees).
Should it += ' bytes'
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alrighty I made formatBytes
. @exterkamp says this should be i18n'd but the other value rendering functions here don't do that yet so I'm gonna defer it here too.
Co-authored-by: Patrick Hulce <patrick.hulce@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 4 i18n
const kbs = this._numberFormatter.format(Math.round(size / 1024 / granularity) * granularity); | ||
return `${kbs}${NBSP2}KB`; | ||
return `${kbs}${NBSP2}KiB`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@connorjclark and I talked about this.
This needs to be i18n'd in the future. Half our "KiB" are translated, and half aren't. We should be consistent and allow these to be translated as well.
This problem exists today, so not blocking for this PR, but it's a TODO.
// Note that 'kb' is historical and actually represents KiB. | ||
const value = Util.i18n.formatBytesToKiB(details.value, details.granularity); | ||
const text = this._renderText(value); | ||
text.setAttribute('title', Util.i18n.formatBytes(details.value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
text.setAttribute('title', Util.i18n.formatBytes(details.value)); | |
textEl.title = Util.i18n.formatBytes(details.value); |
is slightly better here
return this._renderText(value); | ||
// Note that 'kb' is historical and actually represents KiB. | ||
const value = Util.i18n.formatBytesToKiB(details.value, details.granularity); | ||
const text = this._renderText(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
textEl
?
Chrome DevTools is changing its usage of KB (JEDEC, 1 KB = 1024 bytes) to the unambiguous KiB (IEC, 1 KiB = 1024 bytes). We want Lighthouse to be in alignment.
Some web.dev docs that need to update too:
and https://web.dev/performance-budgets-101/ (cc @khempenius)
We don't use
displayUnit: 'kb'
for anything. Do we want to just update all instances of it tokib
? I imagine this would break 0 users.I added a
title
to the byte divs ... yay or nay?