-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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: gzip treemap data #12519
Merged
+231
−53
Merged
report: gzip treemap data #12519
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d5123ca
report: encode data even if very large
connorjclark 267d578
ok
connorjclark d7281c0
rm
connorjclark ff0bfd1
no btoa lol
connorjclark c417fcb
benchmark
connorjclark 8ac3a39
lol
connorjclark 720c427
test
connorjclark f0e8949
pako
connorjclark 6d6e453
fixtest
connorjclark ef3e69e
test
connorjclark c9c60df
minify
connorjclark 585bfa0
Merge remote-tracking branch 'origin/master' into treemap-encode
connorjclark a638270
tweak
connorjclark 9eb78f6
dont use minified
connorjclark d985f61
gzip optional
connorjclark 13a4671
upgrade puppeteer for compression stream
connorjclark 07e3c8d
revert puppeteer upgrade
connorjclark ea226a6
Merge remote-tracking branch 'origin/master' into treemap-encode
connorjclark 5365e53
update
connorjclark a6ff9bb
yay
connorjclark b473636
pr
connorjclark 50ff2f1
names
connorjclark ca16fff
deprecate postmessage
connorjclark 5b2f7d3
rename
connorjclark b8e6b84
tweak
connorjclark c6dafbd
pr
connorjclark 56a55e0
rename
connorjclark 363022e
comment
connorjclark e33568a
rename
connorjclark 941cadb
tweak
connorjclark d55f819
Update types/html-renderer.d.ts
connorjclark b8d8aff
edit
connorjclark f757094
f0a38c0
Merge remote-tracking branch 'origin/master' into treemap-encode
connorjclark d45dc4b
merge
connorjclark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @license Copyright 2020 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/* global self btoa atob */ | ||
|
||
const encode = typeof btoa !== 'undefined' ? | ||
btoa : | ||
/** @param {string} str */ | ||
(str) => Buffer.from(str).toString('base64'); | ||
const decode = typeof btoa !== 'undefined' ? | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
atob : | ||
/** @param {string} str */ | ||
(str) => Buffer.from(str, 'base64').toString(); | ||
|
||
/** | ||
* @param {string} string | ||
*/ | ||
function toBinary(string) { | ||
// const codePoints = [...string].map(c => c.codePointAt(0) || 0); | ||
// return encode(String.fromCharCode(...new Uint8Array(codePoints))); | ||
|
||
const chunkSize = 10000; | ||
let str = ''; | ||
for (let i = 0; i < string.length; i += chunkSize) { | ||
const codeUnits = new Uint16Array(Math.min(chunkSize, string.length - i)); | ||
for (let i = 0; i < codeUnits.length; i++) { | ||
codeUnits[i] = string.charCodeAt(i); | ||
} | ||
str += String.fromCharCode(...new Uint8Array(codeUnits.buffer)); | ||
} | ||
|
||
return encode(str); | ||
} | ||
|
||
/** | ||
* @param {string} encoded | ||
*/ | ||
function fromBinary(encoded) { | ||
// const binary = decode(encoded); | ||
// const bytes = new Uint8Array(binary.length); | ||
// for (let i = 0; i < bytes.length; i++) { | ||
// bytes[i] = binary.charCodeAt(i); | ||
// } | ||
// return String.fromCodePoint(...new Uint16Array(bytes.buffer)); | ||
|
||
const chunkSize = 10000; | ||
let str = ''; | ||
const decoded = decode(encoded); | ||
for (let i = 0; i < decoded.length; i += chunkSize) { | ||
const bytes = new Uint8Array(Math.min(chunkSize, decoded.length - i)); | ||
for (let j = 0; j < bytes.length; j++) { | ||
bytes[j] = decoded.charCodeAt(i + j); | ||
} | ||
str += String.fromCharCode(...new Uint16Array(bytes.buffer)); | ||
} | ||
|
||
return str; | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = {toBinary, fromBinary}; | ||
} else { | ||
self.Base64 = {toBinary, fromBinary}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const Base64 = require('../../../../report/html/renderer/base64.js'); | ||
|
||
/* eslint-env jest */ | ||
|
||
describe('base64', () => { | ||
/** @type {string} */ | ||
function test(str) { | ||
const roundtrip = Base64.fromBinary(Base64.toBinary(str)); | ||
expect(roundtrip.length).toEqual(str.length); | ||
expect(roundtrip).toEqual(str); | ||
} | ||
|
||
it('works', () => { | ||
test(''); | ||
test('hello'); | ||
test('{åß∂œ∑´}'); | ||
test('Some examples of emoji are 😃, 🧘🏻♂️, 🌍, 🍞, 🚗, 📞, 🎉, ♥️, 🍆, and 🏁.'); | ||
test('.'.repeat(125183)); | ||
test('😃'.repeat(125183)); | ||
test(JSON.stringify(require('../../../../../lighthouse-treemap/app/debug.json'))); | ||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🚲 🏠 felt a bit weird to open the base64 file and see compression streams
encoding
text-encoder
text-encoding
any of those feel better to you?
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 thought about renaming it, but the end result is base64'd, it's just that the acceptable input is more than just ascii, so...
idk 👍(rename) 👎 (keep) vote :)
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.
File names are about more than just the format of the functions' return types IMO :)
Perhaps I'm alone though...
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 also think the name of the file is a bit odd. +1 to
text-encoder
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.
TextEncoder.{encode,decode} also has its oddities, and we can't name the global object
TextEncoder
because that exists :)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.
oh right, globals! lol.
text-encoding
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.
Yeah, -1 to
text-encoder
for that reason.I don't care much what it is though.
base64
is fine to me because we are hopefully not going to grow our encodings collection :)text-encoding
works too