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

Improper dependency tracking for sass imports #1451

Closed
Ecco opened this issue Aug 13, 2019 · 6 comments · Fixed by #1452
Closed

Improper dependency tracking for sass imports #1451

Ecco opened this issue Aug 13, 2019 · 6 comments · Fixed by #1452

Comments

@Ecco
Copy link
Contributor

Ecco commented Aug 13, 2019

Steps to reproduce

  1. Run bundle exec nanoc compile
  2. Modify a single file
  3. Run bundle exec nanoc compile again

Expected behavior

  • Goes rather fast (hopefully less than a second)
  • Time taken is the sum of the time it took each "update/create/delete" steps

Actual behavior

Loading site… done
Compiling site…
      update  [0.00s]  output/jobs/index.html

Site compiled in 9.31s.
```

And yes, it really took 10 seconds…

### Details

- There are 324 files in the `content` directory of this nanoc website.
- The `Loading site... done` is super quick.
@Ecco
Copy link
Contributor Author

Ecco commented Aug 13, 2019

Ok, first step towards solving my issue : running bundle exec nanoc compile --verbose shows a lot more info, and some "identical" files which do indeed take a lot of time to build.

Suggestion:

  • Maybe nanoc shouldn't hide "identical" log lines?
  • If the total time is much greater than the sum of lines displayed, maybe nanoc should display "identical lines"? Or suggest a re-run with --verbose?

@denisdefreyne
Copy link
Member

Hey @Ecco, do you have a copy of your site that I could get hold of? (I believe you'd be able to share a private GitHub repository with me.)

@Ecco
Copy link
Contributor Author

Ecco commented Aug 14, 2019

Yeah, I'm trying to do my homework first and if really I can't find anything I'll ask for your help 😄

What I've found so far: the problem comes from a sass file that has a huge list of dependencies that don't make any sense. Here's a small extract of bundle exec nanoc show-data:

item /shared/site/stylesheets/style.sass depends on:
  [   item ] (r___) /en/legal/warranty/index.html
  [   item ] (r___) /favicon.ico
  [   item ] (r___) /shared/site/images/flags/fr.svg
  [   item ] (r___) /shared/site/images/flags/us.svg
  [   item ] (r___) /shared/site/images/flags/uk.svg

I'm trying to figure out where this dependency comes from, so far I haven't found anything intersting.

What happens is that if I modify "/en/legal/warranty/index.html", then nanoc think the sass file needs to be rebuilt. And it's kinda big, so it takes a while. Eventually nanoc figures out it built it for nothing because it's identical to the previous one, so it doesn't log an "identical" line, which causes a discrepancy between the "total" line and the actual sum of logged times.

@Ecco
Copy link
Contributor Author

Ecco commented Aug 14, 2019

Ok, I think I found the bug. It's a big hairy one 😄 It happens when nanoc processes an @import sass directive.

  1. Nanoc processes an @import foobar directive using its sass filter
  2. Sass process this content, and turns back to nanoc, calling Nanoc::Filters::SassCommon::Importer#find_relative
  3. This calls raw_filename_to_item on the same class
  4. Which eventually calls Nanoc::Filters::SassCommon::Importer::raw_filename_to_item_map_for_config
  5. This class methods does this:
items.each do |item|
  if item.raw_filename

And, if I read Nanoc::Filter#depend_on correctly, that's how a filter registers a dependency. For the record, here's the code of this method:

def depend_on(items)
  items.flat_map(&:reps).flat_map(&:raw_path)
  items.each(&:raw_filename)
end

Long story short, the sass filter creates tons of spurrious, random dependencies. This doesn't yield a bad compilation, but it definitely slows things down an awful lot!

@Ecco Ecco changed the title Nanoc takes a really long time to rebuild Improper dependency tracking for sass imports Aug 14, 2019
@denisdefreyne
Copy link
Member

Thank you for the detective work and the quick fix! A release with this fix in it will be out soon.

@denisdefreyne
Copy link
Member

This is now released in Nanoc 4.11.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants