Overhaul option handling - #88
Conversation
commit: |
|
Also I have a question: Are found paths both processed in |
|
i haven't had the time to look at this pr, but answering your question: wouldn't work in most cases. fdir exclude paths are always absolute and filter paths aren't, plus the fact that you wouldn't even find directories in filter unless you set up the options to also receive dirs |
|
Yeah, I tried caching anywhere and the tests started to fail. Damn... |
|
I've realized the way tinyglobby manages it's own options was copy pasted between This also included some tiny restructurings and an additional type called This change reduced the bundle size by another ~350 bytes. ESM dist\index.mjs 9.23 KB
ESM dist\index.mjs.map 20.09 KB
ESM ⚡️ Build success in 18ms
CJS dist\index.js 11.19 KB
CJS dist\index.js.map 20.22 KB
CJS ⚡️ Build success in 19ms
DTS Build start
DTS ⚡️ Build success in 908ms
DTS dist\index.d.mts 1.01 KB
DTS dist\index.d.ts 1.01 KB |
|
I found some more options handling logic in Edit: After reverting the |
|
We are almost at 1KB reduced file size, basically almost 10% reduction. The only question is the behavior of So this question is: Do |
|
yes they do, because those options are meant to default to |
|
Okay, so the |
|
okay! i thought initializing them to |
|
Well, there should always be a balance of package size and performance. If you care too much about package size, it's going to be slow, if you care too much about performance, it's going to be unreadable (because everything theoretically makes the program slower). I know one or two big projects that accidentally introduced this third buggy state of Defining all necessary default options makes the code look bigger, but is the most clean and easy to maintain way. You can define your options type as strict as possible, are able to process it centrally and use the input value with Using this approach made this project almost 1KB smaller with this PR. Speaking of performance: Since objects are dynamically sized and shaped, JS engines introduced the concept of a "shape" to optimize and organize the heap by implicitly defining two objects with the same properties as one fixed "shape" like two instances of a class. This improves performance as the engine becomes aware of what kind of object you want to use. TypeScript helps you utilize this concept better by defining interfaces for your objects or force you to define all properties of a class outside of the constructor to make the shape of an object static. So changing the values of properties is extremely fast, but adding and removing properties with |
|
I tried my best over the last few days to rebase it, but even my vscode has given up half-way through. Has fdir changed the type to |
There was a problem hiding this comment.
i'm not sure when i will fully review this as it's quite complex to figure out, but i will try not to push anything to main before this is done so that we can avoid merge conflicts 👍 for now one small nit
by the way the APIBuilder import fails now due to fdir setting the exports field. if you really need it we can use ReturnType<typeof new fdir()> i guess?
also, it looks like this pr no longer decreases bundle size (it very slightly increases it i think?), but i'm not sure
either way amazing work, will run biome for you once its ready to merge
| debug: !!process.env.TINYGLOBBY_DEBUG, | ||
| cwd: process.cwd(), | ||
| ignore: [], | ||
| // tinyglobby exclusive behavior, should be considered deprecated |
There was a problem hiding this comment.
looks like the comment is in the wrong place 👀
There was a problem hiding this comment.
Actually, no. I copied over the option with the comment from the very beginning of this PR (I guess 0.2.11?). If you want me to remove it, I'm okay with that. I would've shown an older version of defaultOptions, but the git history already broke due to multiple rebases, I guess.
|
Hi, no problem. I'm also struggling to find footing with the massively increased complexity from before. I actually needed the Currently, the branch appears bigger, because I still have the old and new version of I actually got a new PC which finally allows me to run Rust projects, so I can finally lint it myself🎉 |
|
I now migrated to the new version, reduced the size of the fdir options and also added something new: It is important that you not only check for the existence of the fs: {
"readdir": "Hello",
"stat": 5,
"realpath": { "toast": "peanut-butter" }
}I'll leave it as a draft now, because I still want to check if I can still find some code reductions. |
|
I'm officially done! Sadly, the extra options, validation and utilities increased the output size by a small margin (gzipped 300 bytes). Here is the final size comparison: Before: After: I could try to inline things even further, but this would make the code uglier and possibly harder to understand. |
|
I figured out why you wrote This results in a whopping: 1.6% output size reduction for CJS and 1.8% for ESM unminified 🎉 |
|
Okay, now I believe I can't find anything anymore. I had to alter a test, because the |
|
congrats for figuring out the size reduction 🎉! sadly this looks really hard to review due to the git diff shenanigans, would you mind splitting it up into smaller prs (or one new pr with many small commits)? that way we can also avoid problems with merging from main (i see some leftover code from older versions of the library here that was likely introduced that way) since i don't plan to push anything to main before this |
|
I'm very sorry this PR has derailed and got too big. Over the months, it turned into a playground of what could be optimized within Thank you for being so understanding 🙏 |
Hi, me again.
After updating the performance of this project, I decided to reduce the package size even further and clean it further up by overhauling how fdir options are built with the given options and properties.
What did I do?
getPartialMatcherThis reduced the build size from
to
which is around 400b.
It seems like biome doesn't support 32 bit windows (or there is any other bug), so I can't lint and format :(