Skip to content

perf(ldf): resolve each include name once per walk (FastLED incremental 25 s -> 7 s) - #1551

Merged
zackees merged 1 commit into
mainfrom
perf/ldf-resolve-cache
Sep 28, 2026
Merged

zackees merged 1 commit into
mainfrom
perf/ldf-resolve-cache

Conversation

@zackees

@zackees zackees commented Sep 28, 2026

Copy link
Copy Markdown
Member

Refs #1539 and #1537. This is the dominant cost of every non-fast-path FastLED build, e.g. edit a sketch, rebuild.

Problem

fbuild_header_scan::walker::resolve_include resolved each #include reference by is_file()-probing every search path in order. It did this for every reference in every file, in each of four walks per build:

  • collect_defined_macro_names ran twice: once in resolve_with_stats_active_declared, then again inside resolve_with_stats_impl_declared, with identical inputs;
  • LDF pass 1;
  • LDF pass 2.

ESP32 hands the LDF ~400 search paths (the SDK block, FastLED and the framework libraries), so an incremental FastLED build was millions of statx calls. A perf profile of the daemon during an incremental DemoReel100 build puts 67% of all samples under resolve_include → Path::is_file → statx.

Fix (exact, memoization only)

  • WalkState gains an IncludeResolver bound to the search-path list, with two caches:
    • name → search-path resolution. The answer depends only on the name, never on the including file. A quoted include still checks beside the including file first, uncached, as before.
    • realpath memo for the canonical paths used in visited/reached.
  • The cache is dropped if the same WalkState is used with a different search-path list.
  • collect_defined_macro_names_with(seeds, paths, &mut state) runs the textual pre-walk on its own scan cache and visited set, since textual and active scanners must not mix. It shares the resolver, and its result is passed into the passes, so the second identical walk is gone.

Numbers

FastLED DemoReel100, esp32s3, local 16-core box: edit the sketch, then rebuild.

before after
incremental build 20.4–24.9 s 7.0 s
library selection (lib archives → selection) ~17 s (11.6 s pre-pass + 5.3 s passes) 1.2 s
selected libraries FS, I2S, LittleFS, SPI, WiFi FS, I2S, LittleFS, SPI, WiFi (identical)

Blink-sized projects barely change, since their LDF was already small.

Tests

  • w30: a cached search-path result never overrides a sibling quoted include (a/x.h beside the file versus inc/x.h on the search path).
  • w31: a resolver reused with a different search-path list resolves afresh.
  • All 66 fbuild-header-scan tests and all fbuild-library-select tests (lib, perf_tdd) pass.

…erence

The header walker resolved every #include by is_file-probing each search
path, for every reference, in each of the textual pre-walk and the LDF
passes. With ESP32's ~400 search paths that was two thirds of the
daemon's CPU on an incremental FastLED build (~17 s of 25 s).

A name's search-path resolution does not depend on the including file,
so WalkState now memoizes it per search-path list (quoted includes still
check beside the including file first), and memoizes realpath. The
defined-macro pre-walk shares the resolver, and its result is passed to
the passes instead of being walked a second time.

Refs #1539.
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: FastLED/fbuild/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 2bf1c0fd-4342-42af-9190-2c63b79a4823

📥 Commits

Reviewing files that changed from the base of the PR and between c92c6f8 and a4d23d4.

📒 Files selected for processing (3)
  • crates/fbuild-header-scan/src/lib.rs
  • crates/fbuild-header-scan/src/walker.rs
  • crates/fbuild-library-select/src/lib.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 5634455 into main Sep 28, 2026
20 checks passed
@zackees
zackees deleted the perf/ldf-resolve-cache branch September 28, 2026 19:20
zackees added a commit that referenced this pull request Sep 28, 2026
…ry path (#1554)

After #1551 each unique include name was resolved once, but a name no
search path holds (FastLED's many platform-conditional includes) still
cost one stat per search path -- ~400 on ESP32. The resolver now lists
each search root once and only probes the paths whose root holds the
name's first component, in search order; names with ./.. or absolute
paths, and unlistable roots, keep the full probe loop. Keys fold case,
which only widens the candidates each is_file() then confirms.

The defined-macro scan over reached files is parallel too.

Refs #1539.
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant