hypothesis / hypothesis/client

Quote anchoring blocks execution for a long time

Open
#3,919 17 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Mustache
Stars
730
Forks
224
PR merge metrics
No merged PRs in 30d

Description

_Summary of investigation (2021-11-22) - fuzzy quote anchoring can be very inefficient in long documents for short, generic quotes. In this case the quotes include single punctuation marks and whitespace characters. See https://github.com/hypothesis/client/issues/3919#issuecomment-974871178 - @robertknight_

----

### Steps to reproduce
1. this is on a semi-private page that I can share if it would help, but i think this would happen on any page that has a) a lot of text, b) a lot of annotations, and c) the text has been edited so the anchors don't have exact matches.

### Expected behaviour
hypothes.is should load asynchronously and not block page execution while it is loading

### Actual behaviour
The page will partially load and the exact matches will be drawn, but then every other annotation without an exact match for an anchor will be resolved serially while blocking page execution. This means that the page will render the first screen, but then be completely unresponsive for >10 seconds.

20% of the time is network requests, and 60% seems to be the function to resolve imperfect matches.
Screen Shot 2021-11-11 at 11 10 28 AM

Screen Shot 2021-11-11 at 11 10 05 AM

The problem seems to be here:
https://github.com/hypothesis/client/blob/63545fd3c056740c393b4aa14d27cbf0bd8ec12d/src/annotator/anchoring/html.js#L83

I don't know much about promises/async, and I haven't dug through the code to say for sure, but it looks like the problem might be what look like nested promises, and it also doesn't look like the async `querySelector` is being awaited? In any case something is not working with the async implementation there and i unfortunately have to disable it on my page until i find a workaround :(

### Browser/system information
Hypothesis version 1.911.0
Browser: Firefox 94.0.1 and Chrome 95.0.4638.69
OS: macOS 11.6

Thanks in advance, love y'all

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.