-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Transform Performance Slow Especially When we run it on dev mode.. #334
Comments
Reopened and updated the original issue on the typia repo, I'm now suspecting it might be the typia transform itself that's slow. |
@timoxley OH I missed this issue! |
I'll reopen this issue again
I'm curios! If we can use it, this is really great! I'm surprised that the unplugin-typia makes your project's build slow so much. |
I agree. That is why I disabled the feature by default.. |
Another bad thing is that vite transformation is not parallel, it is sequential. |
Yeah maybe we can fix it. When I first implement this plugin, creating |
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 |
maybe you should! |
Hmmm, I'll keep investigating it! |
edit: disregard this! I can get exactly what I want with `Pick`, and this is irrelevant to the pluginPerhaps this is more a IIUC there's two main use-cases for these type checking functions:
The former requires strict, deep checks and is what e.g. I'd like to be able to replace this kind of pattern with a const players: Record<PlayerId, Player> = getPlayers()
const player = player[playerId]
if (!player) throw new Error(`Player not found: ${playerId}`) e.g. const players: Record<PlayerId, Player> = getPlayers()
const player = assert<Player>(player[playerId]) // throw if player isn't found but I don't really need assert to validate all the nested fields on the i.e. before export const isPlayer = (value: unknown): value is Player => {
return typeof value === 'object' && value !== null && (value as any).type === 'PLAYER'
} and I kinda wish 🤔 hm. I guess I could get that right now just using const isPlayer = createIs<Pick<Player, 'type'>> and even with rough types: type PrimitiveKeys<T> = {
[K in keyof T]: T[K] extends object ? never : K
}[keyof T]
const isPlayer = createIs<Pick<Player, PrimitiveKeys<Player>>> Anyway, the original thought was: if Not sure if this thought is helpful or not since I don't think that's even the bottleneck here, but it was just something I was pondering when I saw how a simple inline |
I think typia generates only what you defined in your type definition if you use |
If tsc is slow, it could be improved by using like this: |
@miyaji255 looks interesting |
I originally posted this on the typia repo, samchon/typia#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?unplugin-typia/packages/unplugin-typia/src/core/typia.ts
Line 180 in 9877201
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.The text was updated successfully, but these errors were encountered: