Skip to content

Migrate back to Cow for slightly improved performance#1

Merged
katrinafyi merged 1 commit intorina-forks:refactor-filecheckerfrom
lycheeverse:refactor-filechecker-edits
Aug 30, 2025
Merged

Migrate back to Cow for slightly improved performance#1
katrinafyi merged 1 commit intorina-forks:refactor-filecheckerfrom
lycheeverse:refactor-filechecker-edits

Conversation

@mre
Copy link
Collaborator

@mre mre commented Aug 29, 2025

There's a big chance that the performance difference does not matter, but since this happens in the hot path, I decided to give Cow a try again. 🐮 Turns out it wasn't too awful and is contained within the function, so I'd argue it's worth it. But you'll be the judge. 😅 I'm okay either way.

@katrinafyi
Copy link

Thanks for looking into it! I'll give it a try and see how it goes.

Honestly, this is definitely micro-optimisation because I think resolve_base also ruthlessly copies. But thanks!

Copy link

@katrinafyi katrinafyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I had assumed that using Cow would need more complicated code in assert_resolves. But even with the changed signature, it just works. I think there's some Deref magic happening here :D

I'll merge this next time I'm at the computer. Thanks!

@katrinafyi katrinafyi merged commit 90eacae into rina-forks:refactor-filechecker Aug 30, 2025
4 checks passed
katrinafyi added a commit that referenced this pull request Aug 30, 2025
…ing (lycheeverse#1830)

* chore(file checker): separate resolving and checking for easier testing

this does a simple refactor to break up the `check_path` function.
previously, this had the responsibility of resolving index
files/fallback extensions _and_ checking fragments. this was done in one
step which made it hard to test - in order to test the resolving, we had
to test it indirectly by checking fragments in certain files.

this introduces a new `resolve_local_path` function which only applies
the index file + extensions, so we can use this in unit tests and make
assertions about the resolved path.

this should have no changes to any behaviour.

* rewrite tests to directly test resolve function

this makes the meaning of the tests a bit clearer. rather than going
through fragments, we can directly make assertions about the resolved
file path.

* lint

* refactor(FileChecker): improve path resolution with Cow for better performance (#1)

* extremely opinionated .map usage

---------

Co-authored-by: Matthias Endler <matthias@endler.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants