eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

[Performance] Writing templates is slow because of unbounded concurrency

Open shivjm opened this issue 1 year ago • 1 comments
trafficstars

Operating system

Windows 10

Eleventy

3.0.0-alpha.9

Describe the bug

This use of Promises:

https://github.com/11ty/eleventy/blob/9c3a7619a429f26cc2b449d65209be6d6a23828e/src/Template.js#L751

Means that almost all templates are written at the same time to the disk, which dramatically slows down individual writes. I added a console.time around the write to show this and recorded the output. You can see that some files take a full 15 seconds to write, and the total time for ‘Template Write’ is 15,885ms or nearly 16 seconds with 926 files.

For the sake of testing, I changed just that line to use fs.writeFileSync instead of await writeFile. Here’s the output. The time for ‘Template Write’ dropped to 232ms, with each individual file taking under a millisecond.

Reproduction steps

  1. Create multiple template files.
  2. Run Eleventy.

Expected behavior

Files are written sequentially or with bounded concurrency.

Reproduction URL

No response

Screenshots

No response

shivjm avatar May 01 '24 17:05 shivjm

I think fixing this would also fix #2627.

shivjm avatar May 01 '24 18:05 shivjm

Shipping your PR with 3.0.0-alpha.11

zachleat avatar Jun 10 '24 20:06 zachleat