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

Add support for an optional faster file hashing method in Gatsby core #38891

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/gatsby/src/utils/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ const activeFlags: Array<IFlag> = [
? `Partial hydration is only available in Gatsby V5. Please upgrade Gatsby.`
: `Partial hydration requires React 18+ to work.`,
},
{
name: `FAST_HASHING`,
env: `GATSBY_FAST_HASHING`,
command: `all`,
telemetryId: `FastHashing`,
description: `Hashes file using a faster non-cryptographic method to improve build performance, particularly on sites sourcing large files.`,
experimental: false,
testFitness: (): fitnessEnum => true,
},
]

export default activeFlags
7 changes: 6 additions & 1 deletion packages/gatsby/src/utils/jobs/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ function convertPathsToAbsolute(filePath: string): string {
* Get contenthash of a file
*/
function createFileHash(path: string): string {
return hasha.fromFileSync(path, { algorithm: `sha1` })
if (process.env.GATSBY_FAST_HASHING) {
const stats = fs.statSync(path)
return stats.mtimeMs.toString() + stats.ino.toString()
} else {
return hasha.fromFileSync(path, { algorithm: `sha1` })
}
}

let hasActiveJobs: pDefer.DeferredPromise<void> | null = null
Expand Down