-
Notifications
You must be signed in to change notification settings - Fork 4
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
perf: reduce allocations in MediaType::from_specifier
#7
perf: reduce allocations in MediaType::from_specifier
#7
Conversation
// slower here, so continue to use to_lowercase() | ||
let lowercase_str = ext.to_lowercase(); | ||
match lowercase_str.as_str() { | ||
"ts" => map_typescript_like(path, Self::TypeScript, Self::Dts), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be neat to have a macro that expands "ts"
to "ts" | "TS" | "Ts" | "tS"
... seems to reduce 268ns -> 220ns
Edit: or maybe something like this might be best:
case_insensitive_match!(ext {
"ts" => map_typescript_like(path, Self::TypeScript, Self::Dts),
"mts" => map_typescript_like(path, Self::Mts, Self::Dmts),
...etc...
})
...then that could be a proc macro that generates the most optimal matching strategy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @nathanwhit could tackle that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use https://doc.rust-lang.org/std/string/struct.String.html#method.eq_ignore_ascii_case instead? I think we could just create a macro that checks string length and uses that method for each case, and the compiler would be reasonably good at optimizing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that and it was slower than the match in this case for some reason (I think 40ns slower). It was faster for tsbuildinfo
somewhere else in this file. Edit: Didn't try matching on string length though
This is used a lot in the node resolution.