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

fix(core): re-subscribes to shared pair listener opens a new connection #8120

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Dec 20, 2024

Description

While testing #8110 I noticed that even when preloading, clicking a document would cause a new listener request to be made.

Tracked this down to being caused by the memoization of the shared document pair listener. This PR fixes the issue by:

  • Replacing the connector.complete() trick with instead exposing a _keepalive stream that we merge in with the (memoized & shared) stream of the pair listener. This ensures that the listener connection will be kept open for as long as there are subscribers to the pair object.
  • Moving the delayed reset to the memoized function (returning a pair listener for keyed by document id). This ensures that the delayed reset happens on the memoized observable itself, rather than the connection stream.

What to review

  • Navigate to a document (A) in the Studio
  • Make sure there is a single event source set up with the tag sanity.studio.document.pair-listener
  • Navigate to another document (B)
  • Make sure there is a single new event source set up with the tag sanity.studio.document.pair-listener
  • Go back to document A before 10s has passed
  • Verify that no request was made with the tag sanity.studio.document.pair-listener
  • Stay on document A for more than 10s
  • Verify that the listener connection made for document B is now shut down (timing panel no longer says "Caution: request is not finished yet!")
  • Now, going back to B should trigger a new listener connection again.

Testing

Existing tests should be enough

Notes for release

n/a

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 1:37pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 1:37pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 1:37pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 1:37pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Dec 20, 2024 1:37pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Dec 20, 2024

Component Testing Report Updated Dec 20, 2024 1:34 PM (UTC)

❌ Failed Tests (2) -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 1m 3s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 37s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 50s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 25s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 14s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 1m 6s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 29s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 41s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 13s 3 9 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ❌ Failed (Inspect) 3m 4s 19 0 2
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

github-actions bot commented Dec 20, 2024

⚡️ Editor Performance Report

Updated Fri, 20 Dec 2024 13:35:22 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 25.6 efps (39ms) 25.3 efps (40ms) +1ms (+1.3%)
article (body) 67.6 efps (15ms) 72.5 efps (14ms) -1ms (-/-%)
article (string inside object) 26.3 efps (38ms) 28.6 efps (35ms) -3ms (-7.9%)
article (string inside array) 25.3 efps (40ms) 25.0 efps (40ms) +1ms (+1.3%)
recipe (name) 52.6 efps (19ms) 57.1 efps (18ms) -2ms (-7.9%)
recipe (description) 58.8 efps (17ms) 62.5 efps (16ms) -1ms (-5.9%)
recipe (instructions) 99.9+ efps (5ms) 99.9+ efps (5ms) +0ms (-/-%)
synthetic (title) 19.8 efps (51ms) 20.8 efps (48ms) -3ms (-5.0%)
synthetic (string inside object) 21.3 efps (47ms) 21.3 efps (47ms) +0ms (-/-%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 39ms 46ms 58ms 434ms 676ms 9.8s
article (body) 15ms 18ms 23ms 180ms 209ms 5.0s
article (string inside object) 38ms 41ms 50ms 237ms 256ms 6.8s
article (string inside array) 40ms 42ms 47ms 175ms 162ms 6.7s
recipe (name) 19ms 22ms 27ms 48ms 0ms 7.2s
recipe (description) 17ms 20ms 26ms 33ms 0ms 4.5s
recipe (instructions) 5ms 7ms 10ms 25ms 0ms 3.0s
synthetic (title) 51ms 56ms 59ms 264ms 422ms 12.8s
synthetic (string inside object) 47ms 51ms 57ms 307ms 539ms 8.3s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 40ms 48ms 86ms 399ms 309ms 10.5s
article (body) 14ms 16ms 22ms 92ms 337ms 5.2s
article (string inside object) 35ms 38ms 44ms 144ms 147ms 6.5s
article (string inside array) 40ms 44ms 50ms 226ms 246ms 6.9s
recipe (name) 18ms 19ms 21ms 34ms 0ms 7.2s
recipe (description) 16ms 17ms 18ms 35ms 0ms 4.3s
recipe (instructions) 5ms 7ms 8ms 16ms 0ms 3.1s
synthetic (title) 48ms 49ms 66ms 128ms 515ms 12.4s
synthetic (string inside object) 47ms 50ms 60ms 424ms 748ms 7.9s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

Copy link
Member

@stipsan stipsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a great find!!! 💖

@bjoerge bjoerge marked this pull request as ready for review December 20, 2024 13:47
@bjoerge bjoerge requested a review from a team as a code owner December 20, 2024 13:47
@bjoerge bjoerge requested review from ryanbonial and removed request for a team December 20, 2024 13:47
@bjoerge bjoerge added this pull request to the merge queue Dec 20, 2024
Merged via the queue into next with commit 876d873 Dec 20, 2024
57 checks passed
@bjoerge bjoerge deleted the fix/resubscribe-shared-pair-listener branch December 20, 2024 13:49
pedrobonamin added a commit that referenced this pull request Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants