oxc-project / oxc-resolver

Rust version of webpack/enhanced-resolve
https://oxc.rs/docs/guide/usage/resolver.html
MIT License
122 stars 18 forks source link

perf: improve call to `Path::ends_with` #199

Closed Boshen closed 3 months ago

Boshen commented 3 months ago

Path::ends_with converts the comparator to a Path and compares all components.

    #[must_use]
    pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool {
        self._ends_with(child.as_ref())
    }

    fn _ends_with(&self, child: &Path) -> bool {
        iter_after(self.components().rev(), child.components().rev()).is_some()
    }

module_name in cached_path.path().ends_with(module_name) is guaranteed to be a single component so this overhead can be avoided.

I also changed the order of comparisons to check node_modules because that's the majority of the case.

codspeed-hq[bot] commented 3 months ago

CodSpeed Performance Report

Merging #199 will not alter performance

Comparing perf-ends-with (1e02488) with main (94efa90)

Summary

✅ 2 untouched benchmarks

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.89%. Comparing base (94efa90) to head (be1c77c).

:exclamation: Current head be1c77c differs from pull request most recent head 1e02488

Please upload reports for the commit 1e02488 to get more accurate results.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #199 +/- ## ======================================= Coverage 96.89% 96.89% ======================================= Files 11 11 Lines 2283 2284 +1 ======================================= + Hits 2212 2213 +1 Misses 71 71 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.