Skip to content

refactor: use typeutils for nativeImage serialization - #23693

Merged
codebytere merged 1 commit into
masterfrom
use-typeutils-remote
May 22, 2020
Merged

codebytere merged 1 commit into
masterfrom
use-typeutils-remote

Conversation

@codebytere

@codebytere codebytere commented May 21, 2020 •

Copy link
Copy Markdown
Member

Description of Change

Follow-up to #23666, as stated in PR body. Uses existing typeUtils to serialize nativeImages and improves perf by using a buffer to construct the nativeImage if there is only one representation.

cc @miniak @MarshallOfSound

Checklist

Release Notes

Notes: none

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label May 21, 2020
@codebytere
codebytere force-pushed the use-typeutils-remote branch from 9d44647 to b53f7f0 Compare May 21, 2020 07:26
Comment thread lib/common/type-utils.ts Outdated
const { size, scaleFactor, dataURL } = rep;

// Use Buffer when there's only one representation for better perf.
// This avoids compressing to/from PNG where it's not necessary to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting in knowing more about this, why can't multiple representations use the bitmap buffer?

@codebytere codebytere May 21, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If one uses a buffer to construct an image with multiple representation from multiple dataURLs, the dataURLs themselves are not preserved. If you test:

    const image = nativeImage.createEmpty();

    const dataURL1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=';
    image.addRepresentation({ scaleFactor: 1.0, dataURL: dataURL1 });

    const dataURL2 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==';
    image.addRepresentation({ scaleFactor: 2.0, dataURL: dataURL2 });

    const serializedImage = serialize(image);
    const nonEmpty = deserialize(serializedImage);

    expect(nonEmpty.toDataURL({ scaleFactor: 1.0 })).to.equal(dataURL1);
    expect(nonEmpty.toDataURL({ scaleFactor: 2.0 })).to.equal(dataURL2);

expect(nonEmpty.toDataURL({ scaleFactor: 2.0 })).to.equal(dataURL2); will fail, as the only dataURL associated with the image will be dataURL1. However, there's a perf boost with buffer serialization (see: #23549) so we want to allow it where possible.

@codebytere
codebytere force-pushed the use-typeutils-remote branch 2 times, most recently from 45cb617 to 14121d1 Compare May 21, 2020 16:42
@codebytere
codebytere force-pushed the use-typeutils-remote branch from 14121d1 to defa10d Compare May 21, 2020 16:42
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label May 22, 2020
@codebytere
codebytere merged commit 762f7bc into master May 22, 2020
@release-clerk

release-clerk Bot commented May 22, 2020

Copy link
Copy Markdown

No Release Notes

@trop

trop Bot commented May 27, 2020

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "10-x-y", please check out #23794

@trop

trop Bot commented May 27, 2020

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "9-x-y", please check out #23796

@trop

trop Bot commented May 27, 2020

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "8-x-y", please check out #23797

codebytere added a commit that referenced this pull request May 28, 2020
* refactor: use typeutils for nativeImage serialization (#23693)

* fix: ensure nativeImage serialization main->renderer
@ckerr ckerr mentioned this pull request Jun 8, 2020
5 of 6 tasks
@trop

trop Bot commented Jun 8, 2020

Copy link
Copy Markdown
Contributor

@ckerr has manually backported this PR to "7-3-x", please check out #24021

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants