Skip to content
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

Ajv 8.6.0 makes VSCode IntelliSense extremely slow #1667

Closed
aarbmx6s opened this issue Jul 1, 2021 · 19 comments
Closed

Ajv 8.6.0 makes VSCode IntelliSense extremely slow #1667

aarbmx6s opened this issue Jul 1, 2021 · 19 comments

Comments

@aarbmx6s
Copy link

aarbmx6s commented Jul 1, 2021

After adding to a project Ajv 8.6.0 and importing it in the project makes InteliSense very slow.

Typing some text and getting suggestions for code completions takes ~5-15 sec.

videoplayback.mp4

Example of project

With Ajv 7.2.4 no problem

@epoberezkin
Copy link
Member

epoberezkin commented Jul 2, 2021

Ajv v8 uses somewhat more complex JSONSchemaType type definition than v7, it enables union support and better error reporting.

The compilation time in 5-15 seconds for such a simple example is still difficult to explain - it might be related to how much memory, what CPU you have, so it's ultimately the problem of either TS or VSCode performance. The file with the type definition is only 180 lines of code - it is a complex type, but it should still be compiled in under 1 sec time.

Ultimately, the resource requirements for "compiling as you type" would be higher than just for editing and you need to either free-up memory and/or CPU, re-configure (or change) the editor so it is impacting the UI less.

I do not have such a noticeable performance degradation by the way, with substantially larger schemas than in your video.

Out of curiosity, what is the compilation time when you just compile with tsc? What's the system configuration (memory/CPU/OS)?

In any case, this is not a problem that can or should be addressed in Ajv - the compilation performance is something to be addressed in TS and or VSCode.

@epoberezkin
Copy link
Member

Also, why do you require ajv TS code? You absolutely should require compiled ajv code with import Ajv from "ajv", not the TS source - that would absolutely make performance worse.

@aarbmx6s
Copy link
Author

aarbmx6s commented Jul 3, 2021

Out of curiosity, what is the compilation time when you just compile with tsc? What's the system configuration (memory/CPU/OS)?

I have a large project and compilation time takes ~10 sec
My system: MacBook Pro 13, macOS Big Sur, i5, 16GB RAM.

In any case, this is not a problem that can or should be addressed in Ajv - the compilation performance is something to be addressed in TS and or VSCode.

I tried PhpStorm IDE and the same behaviour. Seems like some problem with TS.

Also, why do you require ajv TS code? You absolutely should require compiled ajv code with import Ajv from "ajv", not the TS source - that would absolutely make performance worse.

I use this example to create a validator based on a type.
Then all schemas are compiling during initialization, except my schemas defined as JSONSchemaType in source code not as JSON schemas.

And after some tests I noticed if JSONSchemaType was imported in somewhere in my code it makes very slow my IDE.
If I do not import JSONSchemaType and define schemas without JSONSchemaType I lose editing features while defining some schema (suggestion and type correction on the fly).

And looks like there is the same problem.

Anyway, thanks a lot!

@epoberezkin
Copy link
Member

epoberezkin commented Jul 3, 2021

Also, why do you require ajv TS code? You absolutely should require compiled ajv code with import Ajv from "ajv", not the TS source - that would absolutely make performance worse.

I use this example to create a validator based on a type.
Then all schemas are compiling during initialization, except my schemas defined as JSONSchemaType in source code not as JSON schemas.

What I meant is that from looking at the video you require ajv from .ts file, not from the compiled JS as in the example… Am I missing something?

That might be the reason for slow compilation…

@aarbmx6s
Copy link
Author

aarbmx6s commented Jul 4, 2021

Also, why do you require ajv TS code? You absolutely should require compiled ajv code with import Ajv from "ajv", not the TS source - that would absolutely make performance worse.

I use this example to create a validator based on a type.
Then all schemas are compiling during initialization, except my schemas defined as JSONSchemaType in source code not as JSON schemas.

What I meant is that from looking at the video you require ajv from .ts file, not from the compiled JS as in the example… Am I missing something?

That might be the reason for slow compilation…

In ajv.ts file ajv is imported properly.
The ajv.ts file content is:

import Ajv, { JSONSchemaType } from 'ajv';

const ajv = new Ajv();

export { ajv };
export { JSONSchemaType };

It is like in my existing project where in my ajv.ts file also exists some utils function like middleware wrappers for expressjs and other tools.

BTW, I attached the project's example :)

@epoberezkin
Copy link
Member

Got it… This is still strange as I don’t have such a long compilation time…

@epoberezkin
Copy link
Member

Please don’t delete the sample project - I will experiment with it later.

@aarbmx6s
Copy link
Author

aarbmx6s commented Jul 4, 2021

Got it… This is still strange as I don’t have such a long compilation time…

Could you tell what IDE do you use?

Please don’t delete the sample project - I will experiment with it later.

No problem!

@epoberezkin
Copy link
Member

Could you tell what IDE do you use?

VSCode

@aarbmx6s
Copy link
Author

aarbmx6s commented Jul 5, 2021

In any case, this is not a problem that can or should be addressed in Ajv - the compilation performance is something to be addressed in TS and or VSCode.

Update: I have done this and it helped. VSCode IntelliSense works properly.

It is really problem with TS

@epoberezkin
Copy link
Member

Ah - interesting...

suzulabo added a commit to suzulabo/announcing.stencil that referenced this issue Aug 23, 2021
@aarbmx6s
Copy link
Author

Not only AJV it's the VSCode itself and not only TS, everything is super slow lately when it comes to intellisense. Nothing works with the latest updates. For days I tried to fix the issues, every language go, java, c++, nodejs, javascript, intellisense makes no sense even if it sometimes work and it keeps hanging. After this switched to Webstorm and must admit VSCode is useless. I rather pay and don't waste my energie on being frustrated. Use webstorm it's worth every penny.

I don't know how VSCode works with other languages but I tried PHPStorm and there is the same problem with the current issue because PHPStorm uses the same typescript engine for code completing :)

@epoberezkin
Copy link
Member

epoberezkin commented Dec 1, 2021

@erikbrinkman - have a look at microsoft/TypeScript#44851 and https://gist.github.com/armanio123/95a33f9ad3286a7d78590eb11af293c4 - this is a suggestion on how to workaround the performance degradation caused by this change: microsoft/TypeScript#30639

Could we maybe use it to improve performance?

Thank you!

@erikbrinkman
Copy link
Collaborator

Yeah, seems pretty simple to split it up. I'll have to figure out how to benchmark...

@erikbrinkman
Copy link
Collaborator

@aarbmx6s I created #1833 based off the gist from that discussion. Could you try using that version of ajv and see if it makes things any better? I was unable to get a performance improvement on your example.

@erikbrinkman erikbrinkman reopened this Dec 5, 2021
@aarbmx6s
Copy link
Author

aarbmx6s commented Dec 5, 2021

@erikbrinkman thanks! I tried your new version but unfortunately the performance still very poor.
Now I'm using typescript@4.5.2 where microsoft/TypeScript#44851 issue was fixed and the performance is significantly faster.

@erikbrinkman
Copy link
Collaborator

@epoberezkin In light of those two facts, it seems unlikely that changing the type will do anything. Maybe it's worth adding a note somewhere about typescript 4.3, or maybe this issue will be enough.

@epoberezkin
Copy link
Member

Thanks a lot for investigating - I think it’s ok to leave it as is, everybody will migrate relatively soon…

@epoberezkin
Copy link
Member

Closing it now

mausworks added a commit to orchest/orchest that referenced this issue Aug 2, 2022
It seems like 8.6.0 has some performance issues with the TypeScript server. This could be a possible fix: ajv-validator/ajv#1667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants