[gatsby-plugin-sharp] fs read/write streams and sharp?
See original GitHub issueSummary
In trying to look into how gatsby handles processing and transforming images, I started to look into process-file.js and noticed that for the most part, reading and writing from disc seems to happen without Node streams. Would using streams help performance wise in this file? Was this already tried out and determined to not be such a great idea?
An example would be changing processFile’s transforms loop to create a sharp transformation pipeline that takes a single read stream, transforms the data, then writes the transformed data to disk. Something like (but not exactly):
const pipeline = sharp();
const readStream = fs.createReadStream(filename);
return transforms.map(async transform => {
const { outputPath, args } = transform
await pipeline.clone().toFile(outputPath);
});
const writeStream = fs.createWriteStream(outputPath);
readStream.pipe(pipeline).pipe(writeStream);
For the purposes of example, I’ve skipped the handling of extra sharp processing but can provide how that’d work too.
Relevant information
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
gatsby-plugin-sharp
Exposes several image processing functions built on the Sharp image processing library. This is a low-level helper plugin generally used by other Gatsby...
Read more >Images in Gatsby Using gatsby-image & gatsby-plugin-sharp
Here's how to work with images in a Gatsby.js website. You'll learn about how to use Sharp and the Gatsby image component for...
Read more >Gatsby Plugin sharp builds fine on MacOS but fails on Debian ...
Ended up solving this - Leaving the cause of issue here so that it can help others - I was using a NodeJS...
Read more >Modify Gatsby's GraphQL data types using ... - Paul Scanlon
yarn add gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-sharp # npm install gatsby-plugin-image ...
Read more >ADDING FEATURES TO YOUR GATSBY SITE - This Dot Labs
gatsby -source-filesystem: This file is used to reading files from your local file system into the Gatsby project. gatsby-transformer-sharp: This ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update:
I think I have some benchmarks now. I’m using gnu-time for these. Node: 12.10.0
The test looks through a directory that contains a bunch of
.png
images, ranging in resolution from 8 x 8 to 3997 x 3997, runs them through sharp, then writes them to another directory as 100 x 100 png images.Original gatsby-plugin-sharp:
Modified gatsby-plugin-sharp:
Test Code:
@KyleAMathews @sidharthachatterjee ,
Sure, I’ll try my best! I have a WIP modification branch that’s mostly completed using streams now. I need to clean up the code and get some benchmarks tied into it, but from what I was seeing, there wasn’t a noticeable difference in speed at all.