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

WIP: Boost performance #1673

Merged
merged 15 commits into from
Oct 21, 2019
Merged

WIP: Boost performance #1673

merged 15 commits into from
Oct 21, 2019

Conversation

kaste
Copy link
Contributor

@kaste kaste commented Oct 4, 2019

Various performance commits.

A 
0 errors across 0 files from annotations. 150 errors in the store
group_by_filename_and_update took 35ms [D]  --> 4ms

0 errors across 0 files from flake8. 150 errors in the store
group_by_filename_and_update took 75ms [D]  --> 23ms

8 errors across 5 files from mypy. 150 errors in the store
group_by_filename_and_update took 113ms [D] --> 16ms
B
0 errors across 0 files from annotations. 150 errors in the store
group_by_filename_and_update took 166ms [D] --> 4ms

0 errors across 0 files from flake8. 150 errors in the store
group_by_filename_and_update took 127ms [D] --> 25ms

58 errors across 5 files from mypy. 150 errors in the store
group_by_filename_and_update took 292ms [D] --> 23ms
C
0 errors across 0 files from annotations. 150 errors in the store
group_by_filename_and_update took 83ms [D]  --> 8ms

0 errors across 0 files from flake8. 150 errors in the store
group_by_filename_and_update took 46ms [D]  --> 7ms

70 errors across 29 files from mypy. 150 errors in the store
group_by_filename_and_update took 975ms [D] --> 42ms

Must be read commit by commit.

Solves #1623 for free in a pragmatic way: if the results change it will open the panel again. Otherwise the panel stays closed.

settings are now generally cached in memory. Greatly improves settings.has_changed which was very cheap and idiosyncratic and now just works as anyone would expect.

Introduces new event lint_result_changed which otherwise is the same as our known 'lint_result' with a cache in front. Notable: Since we usually rely on our settings as a global, t.i. we're never pure anywhere probably, we use a settings 'change-count' as additional cache salt.

Fixes #1623
Fixes #1662
Fixes #1671

@kaste
Copy link
Contributor Author

kaste commented Oct 5, 2019

I don't like the complicated throttler in panel_view so I reverted e803a44 and the previous throttler 2cd32b7.

Now, 5284df0 and the new tip b76c6b0 have the same performance. I think all commits are safe, easy to grasp, except e30f67a is (maybe?) tricky.

With the performance now we basically hit the wall (with warm cache), in that the low ms 5, 6, 8 are spent in group_by_filename_and_update itself and not in the event listeners/view anymore.

@braver
Copy link
Member

braver commented Oct 5, 2019

Nifty. Are you ready for a review here or want to do more work first?

@kaste
Copy link
Contributor Author

kaste commented Oct 5, 2019

This is good enough for review. Sure I can beautify and add some comments and better commit messages ... but I think this works and should be safe.

@braver
Copy link
Member

braver commented Oct 5, 2019

Huh, I was under the impression that accessing settings via the ST API was essentially free. Maybe there is a trick to it, I'm not sure, it's been a while. Maybe load_settings is not free, whereas get any particular value will get it from memory directly. Not doing a load_settings if you don't need to sounds like a good idea anyway.

So, yeah, looks good indeed. I like how you improved the panel view, it's actually a lot simpler to read whereas e803a44 was a bit much.

I'll run with it for a few days, see if any errors turn up.

@kaste
Copy link
Contributor Author

kaste commented Oct 11, 2019

I maybe go for the extra mile and open separate PRs here. Looks like these are good improvements/patches with clear boundaries.

Also looks like that while we have on_lint_result which fires unconditionally we could just invent lint_result_changed. Usually a view doesn't need to update for the same result set. (This wasn't important for single file linters bc it is at least likely that the report changes for the file you're editing, but for multi file linters it is not so. You edit one file and the other ten files reported probably stay the same.) Don't need to do this immediately but it sounds reasonable.

Note: Queries like `views_into_file` are expensive on the worker.
We completely cache the settings in memory. This surprisingly boosts
performance because if we access `load_settings` from the worker
or any other thread we often pay a synchronization penalty of
multiple ms. (Then again these lookups are zero cost.)

The old implementation was also too sloppy because `has_changed`
could only be called once in `on_update` per key. (On the second
call it returned always `False`.)
This partially reverts "2cd32b7 Throttle panel repaints"

We revert the throttler introduces in 2cd32b7, but keep the nice refactoring
around the `draw` function.
Computing `filenames_per_window` is relatively slow, so we try to avoid
that if we can.
@kaste
Copy link
Contributor Author

kaste commented Oct 15, 2019

No separate PR but I actually introduce 'lint_result_changed' bc that's really nicer and makes sense.

Please look at highlights_view bc I compute the gutter region slightly different. I don't see a difference visually. Maybe you know why we computed a 'line-region' for these icons. On my Sublime, it works with the 'normal' region just as well.

LGTM

@braver
Copy link
Member

braver commented Oct 15, 2019

Maybe something about multiple errors on a line, or otherwise overlapping regions?

@kaste
Copy link
Contributor Author

kaste commented Oct 15, 2019

Good idea! The line comes from SL3 where the actual region was used to filter overlapping errors, but we just use the reported line for that now.

@braver
Copy link
Member

braver commented Oct 15, 2019

I’ll try and put it through the ringer later today. Other than that the branch has been really solid for me.

@braver
Copy link
Member

braver commented Oct 15, 2019

Ok, it looked good enough for what I tried now, but I need to try something more complicated with eslint. Will try to break it tomorrow and will report back.

@braver
Copy link
Member

braver commented Oct 16, 2019

Ok, most of this looks and behaves well. I can't remember how to trigger overlapping multi-line errors. I seem to remember that happening with TSLint sometimes, but I haven't done any TypeScript for some time now and don't have any projects lying around.

That said, there is one problem: the tooltips on the gutter no longer work. On the regions themselves they're fine but this doesn't work anymore (screenshot taken on master while hovering over the line number):

Screen Shot 2019-10-16 at 22 20 44

@kaste
Copy link
Contributor Author

kaste commented Oct 17, 2019

You're really a good tester. 👏 👍

@braver
Copy link
Member

braver commented Oct 17, 2019

🙇🏼‍♂️

- For the gutter marks/icons we don't need to compute a line region.
  There is no visual difference if we just use the region we already
  have.

- For the highlights, we extract the 'offending_text' in the backend
  using the virtual view which is just much faster.
- Skip for non lintable views
- Actually only emit when there were any changes
- Broadcast 'filename' instead of 'view'

Notable: the body of this function is basically zero cost in Sublime although
it looks like a lot is happening here. After broadcasting, a normal panel
redraw will occur (if a panel is open).
@kaste
Copy link
Contributor Author

kaste commented Oct 17, 2019

Fixed.

@braver
Copy link
Member

braver commented Oct 17, 2019

Nice! Let's 🛥 this!

@kaste
Copy link
Contributor Author

kaste commented Oct 17, 2019

Workflow question: How do you checkout after I force-push?

@braver
Copy link
Member

braver commented Oct 18, 2019

Well usually I just pull and then notice it doesn’t fast-forward. So then I switch to master, remove the branch, and checkout the branch again.

@kaste kaste merged commit 9860713 into master Oct 21, 2019
@kaste kaste deleted the boost-performance branch October 21, 2019 09:42
@kaste
Copy link
Contributor Author

kaste commented Oct 21, 2019

🙌

(After force-push, I reset --hard to upstream, but also not without this oh shit, I didn't want that moment.)

@kaste kaste added this to the next milestone Oct 21, 2019
@braver
Copy link
Member

braver commented Oct 21, 2019

Wanna ship this now as a minor release?

@kaste
Copy link
Contributor Author

kaste commented Oct 21, 2019

I'm on it right now

@braver
Copy link
Member

braver commented Oct 21, 2019

🎉

@kaste kaste added the 👀 Features and changes worth looking at label Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 Features and changes worth looking at
2 participants