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

feat: use hashed folder names instead of filenames. closes #6232 #8808

Merged
merged 4 commits into from
Oct 29, 2018

Conversation

Sekhmet
Copy link
Contributor

@Sekhmet Sekhmet commented Oct 4, 2018

Related issue: #6232

@LekoArts mentioned two ways of implementing it (one that concatenates argsDigest with contentDigest and other that uses contentDigest as one directory and argsDigest as another child so images are grouped together and it limits the number of directories in static directory). This PR implements the latter.

Performance impact

I measured the performance of original solution and one from this PR 5 times (and ignoring first build after changing gatsby version) for each (every time cleaning the cache) by running gatsby build on example using-gatsby-image.
Tested on Linux, Ryzen 2700X and 970 EVO.

Original (2.0.18)

  • 14.70
  • 14.08
  • 13.65
  • 14.22
  • 13.80

Average: 14.09

This PR:

  • 13.77
  • 13.51
  • 13.61
  • 13.78
  • 13.66

Average: 13,666

So this results in 3% improvement in build times (it might be just luck, but at least it doesn't increase build time).

expect(result.src.indexOf(file.name)).toBe(8)
expect(result.srcSet.indexOf(file.name)).toBe(8)
expect(result.src.indexOf(file.name)).toBe(19)
expect(result.srcSet.indexOf(file.name)).toBe(19)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those had to be changed because the strings changed from:
/static/test-1234-7bb67.png
to
/static/1234/7bb67/test.png
So now file name starts at index 19.

Copy link
Contributor

@pieh pieh Oct 11, 2018

Choose a reason for hiding this comment

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

maybe we should adjust this test to test that final part of path is same as source file? i.e.
expect(path.parse(result.src).name).toBe(file.name) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

and similiar with srcSet - probably would need some processing to split by , and then space or something like that

Copy link
Contributor

@DSchau DSchau left a comment

Choose a reason for hiding this comment

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

Woo hoo; this looks great, thank you!

@DSchau DSchau merged commit 2a66958 into gatsbyjs:master Oct 29, 2018
@DSchau
Copy link
Contributor

DSchau commented Oct 29, 2018

Successfully published:
 - gatsby-plugin-sharp@2.0.10
 - gatsby-source-contentful@2.0.8
 - gatsby-transformer-sqip@2.0.5
lerna success published 3 packages

gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
 (gatsbyjs#8808)

**Related issue:** gatsbyjs#6232

@LekoArts mentioned two ways of implementing it (one that concatenates `argsDigest` with `contentDigest` and other that uses `contentDigest` as one directory and `argsDigest` as another child so images are grouped together and it limits the number of directories in `static` directory). This PR implements the latter.

### Performance impact
I measured the performance of original solution and one from this PR 5 times (and ignoring first build after changing gatsby version) for each (every time cleaning the cache) by running `gatsby build` on example [using-gatsby-image](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-gatsby-image).
Tested on Linux, Ryzen 2700X and 970 EVO.

#### Original (`2.0.18`)
- `14.70`
- `14.08`
- `13.65`
- `14.22`
- `13.80`

**Average:** `14.09`

#### This PR:
- `13.77`
- `13.51`
- `13.61`
- `13.78`
- `13.66`

**Average:** `13,666`

So this results in 3% improvement in build times (it might be just luck, but at least it doesn't increase build time).
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