Refactor Barry, Refactor ⚡
Changed
Improve Quick Fixes performances
We've optimized the way we determine which refactorings can be executed at your current cursor position. This is an Abracabra key feature.
Every time you move your cursor on the code, we propose you the relevant refactorings through the VS Code Quick Fixes (aka, the lightbulb 💡). This process was taking quite some time, which was causing 2 issues:
- On large files (> 1000 LOC), it would take many seconds to propose you anything. This is lon. And let's be honest, legacy code we're dealing with frequently comes as large files we want to refactor.
- Each new refactoring was adding a bit more of computing. Today, that's around 20 refactorings. If we want to add more, we add to improve performances first, so the extension stays usable.
In short, 2 things were improved:
- We now only parse the code once, instead of each refactoring parsing the code again.
- We shortcut the refactoring execution, so we save a bunch of time on the transformation part too.
As for every performance optimization, you need to measure it or it didn't happen! Overall, here's what it looks like:
File size | Execution time before | Execution time after | Gain |
---|---|---|---|
Small (70 LOC) | 200ms | 40ms | -80%, 5 times faster |
Large (2.400 LOC) | 6s | 350ms | -94%, 17 times faster |
Move Statements now handles one-liners more intuitively
Consider following code:
const user = {
firstName: "John",
lastName: "Doe",
age: 24
};
const rights = { admin: false, moderator: true };
Before, if you had the cursor on admin
and you tried to move the statement up, you'd have swapped the parameters:
const user = {
firstName: "John",
lastName: "Doe",
age: 24
};
const rights = { moderator: true, admin: false };
But what you probably intended to do was to swap the two variable declarations. From usage, we think "Move Statements" more as something you'd like to use to move things up or down. If things are at the same line, you certainly don't expect them to move.
The behaviour was surprising, so it was improved. Now, the same operation will generate:
const rights = { admin: false, moderator: true };
const user = {
firstName: "John",
lastName: "Doe",
age: 24
};
However, if your cursor is now on lastName
and you move the statement down, it will still produce the following code since statements are on different lines:
const rights = { admin: false, moderator: true };
const user = {
firstName: "John",
age: 24,
lastName: "Doe"
};
Noticed how it handles the trailing comma? Ok, that was already here. But it's still super neat!