Skip to content

Conversation

@wchargin
Copy link
Contributor

Summary:
When viewing large graphs in Chrome, clicking the “Download PNG” button
could the error message, “Failed - Network error”. This is because
Chrome does not support downloading large data-URLs. Chrome does,
however, support downloading large object URLs, so this patch makes the
appropriate change to use that API instead.

Test Plan:
Generate the audio_demo data and open the wave:01;sine_wave graph in
TensorBoard in Chrome. Transitively expand all node groups. Then, click
“Download PNG”. Before this patch, this consistently failed to download.
After this patch, it downloads and image with the correct contents.

Also tested in Firefox.

wchargin-branch: graph-download-png-blob

Copy link
Contributor

@nfelt nfelt left a comment

Choose a reason for hiding this comment

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

cc @stephanwlee

If this change is worth doing here perhaps we should do it for the scalar chart download as SVG feature too? Those charts are going to be smaller in typical cases but for a really enormous number of runs they could also get fairly large. It would also seem to more "properly" address #1601.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, for the scalar plot download buttons, we use a drop-down menu as the trigger to generate the URL so that it's a two-click process. If we did something similar for the graph it would be possible to use toBlob() and just disable the actual download click target until the synchronous call completes.

Maybe it's not worth it, but I have to imagine toBlob() might be faster than iterating over each character in the blob by hand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of creating a single-chart string for each element of data, can we just change the index to charCodeAt()? E.g. what this does: https://stackoverflow.com/a/21797381/1179226

It seems almost guaranteed to be cheaper to simply index the string at different points versus sub-slicing the string at then indexing into the sub-slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call—this cuts out almost all of the overhead. (Now looking at
~520ms with this code vs. ~500ms for toBlob.) Nice to have even if the
code isn’t performance-critical.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great. Nice to have those numbers since then I guess toBlob isn't much advantage anyway.

@wchargin wchargin force-pushed the wchargin-graph-download-png-blob branch from 4c7d749 to 0f94aff Compare November 14, 2018 01:28
// URL.
const dataUrl = this.downloadCanvas.toDataURL("image/png");
const prefix = dataUrl.slice(0, dataUrl.indexOf(","));
if (!prefix.endsWith(":base64") && !prefix.endsWith(";base64")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in which case does the prefix end with ":base64"? maybe the mdn doc is incomplete: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#Syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I seem to recall having seen data URIs that do not specify a media type
and are of the form data:base64,<data>, even though they really should
be data:;base64,<data>. But on further thought I suppose that those
are technically valid data URIs whose media type is base64 and whose
encoding is textual, not base64, so it would be better to fail here
(which is the more conservative action, anyway). Will patch.

Summary:
When viewing large graphs in Chrome, clicking the “Download PNG” button
could the error message, “Failed - Network error”. This is because
Chrome does not support downloading large data-URLs. Chrome does,
however, support downloading large object URLs, so this patch makes the
appropriate change to use that API instead.

Test Plan:
Generate the `audio_demo` data and open the `wave:01;sine_wave` graph in
TensorBoard in Chrome. Transitively expand all node groups. Then, click
“Download PNG”. Before this patch, this consistently failed to download.
After this patch, it downloads and image with the correct contents.

Also tested in Firefox.

wchargin-branch: graph-download-png-blob
@wchargin wchargin force-pushed the wchargin-graph-download-png-blob branch from 0f94aff to 4ab62c7 Compare November 14, 2018 03:07
@wchargin wchargin merged commit 08a157f into master Nov 14, 2018
@wchargin wchargin deleted the wchargin-graph-download-png-blob branch November 20, 2018 00:10
stephanwlee pushed a commit to stephanwlee/tensorboard that referenced this pull request Dec 13, 2018
Summary:
When viewing large graphs in Chrome, clicking the “Download PNG” button
could the error message, “Failed - Network error”. This is because
Chrome does not support downloading large data-URLs. Chrome does,
however, support downloading large object URLs, so this patch makes the
appropriate change to use that API instead.

Test Plan:
Generate the `audio_demo` data and open the `wave:01;sine_wave` graph in
TensorBoard in Chrome. Transitively expand all node groups. Then, click
“Download PNG”. Before this patch, this consistently failed to download.
After this patch, it downloads and image with the correct contents.

Also tested in Firefox.

wchargin-branch: graph-download-png-blob
stephanwlee pushed a commit that referenced this pull request Dec 14, 2018
Summary:
When viewing large graphs in Chrome, clicking the “Download PNG” button
could the error message, “Failed - Network error”. This is because
Chrome does not support downloading large data-URLs. Chrome does,
however, support downloading large object URLs, so this patch makes the
appropriate change to use that API instead.

Test Plan:
Generate the `audio_demo` data and open the `wave:01;sine_wave` graph in
TensorBoard in Chrome. Transitively expand all node groups. Then, click
“Download PNG”. Before this patch, this consistently failed to download.
After this patch, it downloads and image with the correct contents.

Also tested in Firefox.

wchargin-branch: graph-download-png-blob
stephanwlee added a commit that referenced this pull request Mar 8, 2019
Data uri in the link for download has given us some trouble with
encoding and length limitations. We want to use the ObjectURL like
PR #1610 that is more durable to aforementioned limitations.

Related to #1601.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants