ony3000 / prettier-plugin-classnames

A Prettier plugin that wraps verbose class name based on the `printWidth` option.
MIT License
99 stars 0 forks source link

Performance optimization #69

Closed nikolailehbrink closed 3 weeks ago

nikolailehbrink commented 1 month ago

We would love to integrate this plugin into our company's codebase, which is quite large. I tested its speed along with prettier-plugin-merge and prettier-plugin-tailwindcss to handle class wrapping.

Here are the results:

The significant slowdown makes it difficult for us to justify using the plugin, despite the potential for a slightly improved developer experience. Are there any performance optimizations planned?

Thank you for the plugin and best regards.

ony3000 commented 1 month ago

Hello! I don't have a planned schedule right now, but I've been thinking about optimizing performance.

As you can see from the flowchart, the flow that performs the most transformations calls Prettier's format function at least twice. (And in reality, even during the line wrapping stage, it is called at least once per target class name.)

So, in my opinion, it would be good to reduce the number of calls to the format function during the line wrapping stage, and ultimately it would be best if I could produce the expected result without double formatting.


In current plugins, setting the endingPosition option to relative or absolute will be slightly faster than absolute-with-indent.

ony3000 commented 1 month ago

Oh, there is an experimental speed improvement method I thought about a while ago, but currently this method can only be introduced in JavaScript or TypeScript.

What is the approximate proportion of each language that makes up your company's codebase?

nikolailehbrink commented 1 month ago

Oh, there is an experimental speed improvement method I thought about a while ago, but currently this method can only be introduced in JavaScript or TypeScript.

What is the approximate proportion of each language that makes up your company's codebase?

Actually it is only TypeScript, would be pretty nice 👍

ony3000 commented 3 weeks ago

@nikolailehbrink v0.7.2 has been released, check it out!

After upgrading the version, try enabling the experimentalOptimization option.

An experimental method I had previously considered was the introduction of a biome formatter. However, after investigating the execution time, I thought that it would be possible to optimize the internals of the core parts, so I did not introduce biome.

nikolailehbrink commented 2 weeks ago

Hi @ony3000, thank you very much for the optimizations! Tried it out and it's a lot faster than before! Thank you! 👍