Refactor trackViews() to reliably remove views
Created by: lguychard
Fixes #4064
Refactors trackViews()
to stop relying on a ViewResolver
's selector to detect
removed views. We now inspect removedNodes
to see if any of the removed nodes
is a known view, or contains one or more known views.
With this refactor, the viewStates
logic is now encapsulated within trackViews()
,
which simply emits every added views as a ViewWithSubscriptions
, and takes care of calling
view.subscriptions.unsubscribe()
when the view is removed from the page. This prevents
the consumer from having to reimplement the viewStates
pattern.
Test plan: The view addition/removal logic is well tested by existing unit tests, but performance should be benchmarked as view removal is now more expensive.
TODO:
-
Fix remaining failing test handleContentViews() › detects addition, mutation, and removal of content views
-
Consider consolidating code_views.test.ts
withviews.test.ts
Merge request reports
Activity
Created by: lguychard
I've looked at some profiles and interestingly, this performs consistently better than the status quo.
Test protocol:
- Start on !2344 (merged), make sure all 75 code views are added
- Click to navigate to the "Conversation" tab
- Profile from mouseup to the end of the following animation frame
Baseline: no Sourcegraph extension activated:
Sourcegraph dev extension built from
master
:Sourcegraph dev extension built from this branch:
Another takeaway is that GitHub performance for this user action (switching between tabs on a large PR) is bad to start with, and we make it at least 2x worse
Created by: codecov[bot]
Codecov Report
Merging #4371 into master will decrease coverage by
0.02%
. The diff coverage is85.58%
.Impacted Files Coverage Δ browser/src/libs/code_intelligence/text_fields.tsx 88.09% <100%> (-1.27%)
...r/src/libs/code_intelligence/code_intelligence.tsx 70.31% <80%> (-0.06%)
...rowser/src/libs/code_intelligence/content_views.ts 94.11% <91.3%> (-5.89%)
browser/src/libs/code_intelligence/views.ts 96.42% <95%> (-3.58%)
cmd/gitserver/server/serverutil.go 49.15% <0%> (-2.65%)
cmd/repo-updater/repos/syncer.go 78.53% <0%> (-2.1%)
pkg/diskcache/cache.go 44.09% <0%> (-1.23%)