weird Eleventy build times

Question for Eleventy peeps: do you know why my build times seem so strange? Or is this normal?

When I first run eleventy --serve it seems really long:
Copied 10 files / Wrote 47 files in 15.52 seconds (330.2ms each)

But if I delete the output folder or empty it before running eleventy --serve it’s 10 times faster:
Copied 10 files / Wrote 47 files in 1.52 seconds (32.3ms each)

When I edit a file with the sever running it’s fastest (which I’d expect):
Copied 10 files / Wrote 47 files in 0.19 seconds (4.0ms each)

Why is the first build 10 times longer if the output folder exists when I first run the command? This doesn’t seem right to me, but I don’t really know where to start looking and I’ve struggled to implement the debug (although I haven’t tried recently).

That is peculiar! You’d definitely expect the completely fresh build to take longer than ones where the output directory already exists. I’ve never seen anything like this myself.

Couple of things come to mind that might help nail down what’s causing this:

  1. Is it possible that Eleventy is building the output directory (when it shouldn’t)?
    • Have you modified the input or output directory in your config file?
      That’s typically done in the config file’s return statement, e.g.
      return {
          dir: {
              input: "src",
              output: "_site",
          }
      }
      
    • Maybe try instructing Eleventy to ignore the output directory in a .eleventyIgnore file:
      _site/
      
  2. What version of Eleventy are you using?
  3. Do you have Incremental Builds enabled? (with the --incremental flag)
  4. Are you able to share the source code? e.g. a public repository
  5. If you’re able to get debug mode working, are you able to share the output?
    DEBUG=Eleventy* npx @11ty/eleventy
    

If you want, the folks in the Eleventy Discord might have some better ideas than I do!

1 Like

Thanks! Let me go through these one by one…

  1. This is what I have for my input/output directories, which matches the folder structure I’m using (adding an .eleventyIgnore file didn’t change anything):
// Set custom directories for input, output, includes, and data
dir: {
   input: "content",          // default: "src"
   includes: "../_includes",  // default: "_includes"
   data: "../_data",          // default: "_data"
   output: "_site",
   layouts: "../_includes/_layouts"
}
  1. I’m on v2.0.1.
  2. I don’t – I tried adding it, but it didn’t make a difference to the first build time. Subsequent builds when I changed a single file were even shorter, though, as expected: Wrote 1 file (skipped 55) in 0.08 seconds (v2.0.1)
    a. I also tried --ignore-initial, which uh… was weird? It doesn’t seem like actually writing files is the problem: Copied 10 files / Wrote 0 files in 15.35 seconds (v2.0.1)

So I tried removing all of my passthrough/copying in eleventyConfig, and got: Wrote 0 files in 0.28 seconds (v2.0.1)

So I guess I’m doing passthrough/copying wrong? This is what I have in my config:

// Copy `content/css/style.css` to `_site/style.css`
eleventyConfig.addPassthroughCopy("content/css/");

// Copy favicon stuff
eleventyConfig.addPassthroughCopy("content/favicon.ico");
eleventyConfig.addPassthroughCopy("content/favicon/");
eleventyConfig.addPassthroughCopy("content/site.webmanifest");

// Copy over images (for now)
// eleventyConfig.addPassthroughCopy("content/img/");

// Copy robots.txt
eleventyConfig.addPassthroughCopy("content/robots.txt");

Okay, I thought maybe it was because my passthrough/copy files are in the main source directory, so I moved them. That seemed to temporarily fix it, but now it’s back to being slow when I first run eleventy.

Order of events:

  1. Run eleventy --serve with files in output folder: very slow. Quit running server.
  2. Delete output director and config code copying files in passthrough.
  3. Run eleventy --serve: fast. Quit running server.
  4. Re-enable passthrough.
  5. Run eleventy --serve: fast. Quit running server.
  6. Run eleventy --serve: very slow. Quit running server.

So… it’s slow specifically when the passthrough/copied files are already present in the output folder. Very weird, I will try asking in the discord!