Skip to content
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

perf(gatsby-plugin-image): Optimise image size functions #27544

Merged
merged 2 commits into from
Oct 19, 2020

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Oct 19, 2020

The current way we get the sizes of input images is very inefficient, particularly with large source images. This PR adds a much faster async function, which can be used by fixed(), which is already async. It also optimises the sync version, which we can't currently remove because it's used in various sync functions.

The results of benchmarking the various options:

Implementation Time for 100x reads of 15MB image (ms)
Current sync 8600
Optimised sync* 470
Async* 87

* This PR

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 19, 2020
@LekoArts LekoArts added topic: media Related to gatsby-plugin-image, or general image/media processing topics type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement. and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Oct 19, 2020
pvdz
pvdz previously approved these changes Oct 19, 2020
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

omg ship it

packages/gatsby-plugin-sharp/src/index.js Show resolved Hide resolved
packages/gatsby-plugin-sharp/src/index.js Show resolved Hide resolved
packages/gatsby-plugin-sharp/src/index.js Show resolved Hide resolved
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

👍 👍 👍 👍 👍 👍 👍

@ascorbic ascorbic added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Oct 19, 2020
@gatsbybot gatsbybot merged commit 8752477 into master Oct 19, 2020
@delete-merged-branch delete-merged-branch bot deleted the perf/image-size branch October 19, 2020 11:13
@pvdz
Copy link
Contributor

pvdz commented Oct 19, 2020

Published in [email protected]

pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
)

* perf(gatsby-plugin-image): Optimise image size functions

* Add test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: media Related to gatsby-plugin-image, or general image/media processing topics type: feature or enhancement Issue that is not a bug and requests the addition of a new feature or enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants