Open timoxley opened 2 months ago
Reopened and updated the original issue on the typia repo, I'm now suspecting it might be the typia transform itself that's slow.
https://github.com/samchon/typia/issues/1303#issuecomment-2383941395
@timoxley OH I missed this issue! I think the transformation is slow because this transformation depends on tsc. I implemented some extra feature for speed in this plugin like file skipping, caching, and so on. But, the tsc itself is slow so I cannot deal with it. So, all we can do is improve typia itself! (Now that oxc can handle dts, I'm thinking it will be faster if rusty-typia can do it, but when will it come out? Or should I just make it ?
I'll reopen this issue again
I also notice that the unplugin-typia cache appears very fragile, with any small change it seems to cause a cache miss on everything. I wonder why it's so sensitive? and whether it could use the built-in caches for rollup/vite/tsc etc?
I'm curios! If we can use it, this is really great!
In dev mode, if you don't change file, unplugin-typia doesn't process it again, so caching in vite
works fine.
I'm surprised that the unplugin-typia makes your project's build slow so much. Hmm, I just want to help you, but idk how can I do this..
caching is fragile.
I agree. That is why I disabled the feature by default.. https://github.com/ryoppippi/unplugin-typia/issues/224
Another bad thing is that vite transformation is not parallel, it is sequential.
I had a quick poke around the codebase and I wonder if the problem might be related to creating a new ts.host/ts.program for each file ([id]), rather than a single program for all the files?
Yeah maybe we can fix it. When I first implement this plugin, creating ts.program
with multiple id didn't work, so I implemented it like this.
Can we improve it?
Oh wait, I found that unplugin-typia gets slower in my project! Let me think...
hm I tried a few combinations of up/downgrading both the plugin (to 1.0.0) and typia (random versions between 7.x -> 4.0.1) but didn't spot a clear point where the performance degraded significantly. I wonder if it's tsc or some other dependency
(Now that oxc can handle dts, I'm thinking it will be faster if rusty-typia can do it, but when will it come out? Or should I just make it ?
maybe you should!
Hmmm, I'll keep investigating it! Thank you for your reporting and sponsoring me!!
I think typia generates only what you defined in your type definition if you use assert
function, not equal
. Does this what you mean?
If tsc is slow, it could be improved by using WatchCompilerHost
.
like this: https://github.com/miyaji255/hono-typia-openapi/blob/main/src/plugin/index.ts
@miyaji255 looks interesting Do you want to contribute it?
I originally posted this on the typia repo, https://github.com/samchon/typia/issues/1303 but it's probably more appropriate here.
I have a small vite/vitest application with a handful of tests. The tests take a long time to cold-start and it appears they are getting slowed down by the typia transform: ~15 seconds for ~15 passes, with about 5 files? That seems awfully slow to me, like it must be doing something very inefficient to end up like that? 🤷 What is it doing with all those cpu cycles?
Is there something that can be tweaked to make it transform faster, e.g. more parallelism, reduce repeated work or something, or is this perhaps a limitation of typescript transform? Any suggestions or additional information I can provide?
AFAICT I'm on the latest version of relevant packages.
I had a quick poke around the codebase and I wonder if the problem might be related to creating a new ts.host/ts.program for each file (
[id]
), rather than a single program for all the files?https://github.com/ryoppippi/unplugin-typia/blob/9877201c8e456f25c2656a9eebd00b53537cfda3/packages/unplugin-typia/src/core/typia.ts#L180
Not sure if that would make any difference, just guessing.
I also notice that the
unplugin-typia
cache appears very fragile, with any small change it seems to cause a cache miss on everything. I wonder why it's so sensitive? and whether it could use the built-in caches for rollup/vite/tsc etc?Also, I tried disabling this plugin in vite and using https://github.com/herberttn/vite-plugin-typescript-transform, hoping that it would pick up on the
plugins.transform
in mytsconfig.json
and do the transforming with the rest of the typescript transpiling, but this didn't seem to work and I'm not sure why.