Use browser APIs to calculate Blazor's download size#19547
Use browser APIs to calculate Blazor's download size#19547pranavkm merged 1 commit intoblazor-wasmfrom
Conversation
| logToConsole() { | ||
| logStatistics() { | ||
| // Used by test \ benchmarking infrastructure | ||
| const onDownloadStats = window['Blazor']._internal.downloadStats; |
There was a problem hiding this comment.
This seemed "easy" to do, but if there's a better way to approach this, let me know.
| const query = new URLSearchParams(window.location.search); | ||
| const group = query.get('group'); | ||
| const resultsUrl = query.get('resultsUrl'); | ||
| (async function() { |
There was a problem hiding this comment.
Most of this is just whitespace changes.
| @@ -0,0 +1,15 @@ | |||
| export function getBlazorDownloadSize() { | |||
There was a problem hiding this comment.
Again, if there's a better way to do this, I'd be happy to use it. This launches a page in an iframe that wires up the new hook that I added. The contents of the iframe are slightly different because we need to hook up the callback after Blazor's scripts have been initialized, but before downloads happen. The instance of chrome in docker does caching correctly, so relying on caching to happen isn't problematic.
javiercn
left a comment
There was a problem hiding this comment.
I think this deserves a more in-depth discussion. There are alternative ways we can do this, that feel simpler to me:
- Skip .gz files when computing the size (as those are compressed files).
- Use chrome Remote DevTools Protocol to query the size of the downloaded bits.
I wanted to avoid calculating the sizes in the Benchmark test. It's easy to miss updating the benchmark if we happen to change Blazor's publishing.
That sounds nifty. How does this work? |
I agree. This approach is a bit awkward since it couples us to some internal implementation details, plus it's unable to measure the actual total size including As well as @javiercn's suggestions, another possibly simpler alternative would be to use the
That last expression will give you all the HTTP requests, including for the initial HTML. You can observe both If you just want the total transferred size, it's |
5955650 to
7296a03
Compare
| const app = new BlazorApp(); | ||
| try { | ||
| await app.start(); | ||
| const downloadSize = app.window.performance.getEntries().reduce((prev, next) => (next.encodedBodySize || 0) + prev, 0); |
There was a problem hiding this comment.
@SteveSandersonMS the performance trick helped.
|
This has been updated. |
|
FYI @sebastienros |
The publish sizes in our Benchmarks have been broken since the change to the output structure. Looking at the size on disk is also a little cumbersome, since we have to not double count. It seems like it's much more useful to measure the network download size instead.