-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Refactor/speed improvement #92
Refactor/speed improvement #92
Conversation
Since the local file system is not likely to change during the execution of this plugin, we only need to execute this synchronous function once for each distinct patterns argument.
Regular expressions are expensive to construct. Since the same regular expression is used multiple times, we can construct it once and re-use.
Hi @beaunus, |
@beaunus, I just tried your PR but it'll not keep the "imported" classes list up to date until I restart VSCode... Similar performance issue(s) were already addressed with this specific part of the plugin, it lead to use Maybe I could extract the |
"Maybe I could extract the REFRESH_RATE (default is 5s) as an option" Great idea. Thank you. |
@beaunus , try |
Thank you @francoismassart . Is it possible to include the extracted |
@beaunus => |
From |
Let me know how it works for you @beaunus |
Thank you @francoismassart . With the extracted ☝️ With this change, the default In other words, I propose that we move forward with #93 . Maybe we don't need the extracted What do you think? |
Refactor: Memoize generateClassnamesListSync
This is my first contribution to this repository. Please excuse any mistakes or lack of awareness. 🙏 I suspect that this solution might not be acceptable. I.e. memoizing this function might actually break how the plugin works. 🤔
This fix seems simple enough that the PR itself is the best way to identify the problem and propose a solution.
Description
My team uses
eslint-plugin-tailwindcss
for a project with ~400 files.I observed that when we started using this plugin, the execution time for
eslint
changed dramatically.eslint-plugin-tailwindcss
29 seconds
eslint-plugin-tailwindcss
684 seconds
Investigation
I wanted to know what function calls are taking the most time. I ran
eslint
(with the plugin engaged) on a subset of files. I used the Google Chrome profiler.It seemed clear that the most expensive function calls were
readdir
. The piece of code within the plugin that calledreaddir
wasgenerateClassnamesListSync
.I added some console logs to see what
generateClassnamesListSync
was doing.🎉
generateClassnamesListSync
was taking many seconds for each invocation. And, it always returned the same result. Thus, it seemed like memoization would be an easy fix. 👈 Memoization is the essence of this PR.With the fix, I am able to run
eslint
on the entire codebase, and it takes about the same amount of time as before.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
There is no logical change whatsoever, so the existing tests should be sufficient.
Checklist:
If possible, I think this code change should be integrated and released as a patch for all major versions.