hypothesis / client

The Hypothesis web-based annotation client.
Other
635 stars 196 forks source link

Anchoring is very slow on certain documents/URLs #189

Closed robertknight closed 3 years ago

robertknight commented 7 years ago

Steps to reproduce

  1. Go to https://www.nytimes.com (which has 27 public annotations at the time of writing)
  2. Activate Hypothesis

Actual behaviour

The browser hangs for several seconds after annotations are fetched and before they are identified as Orphans. Firefox' profiler shows a large amount of time being spent in diff-match-patch's fuzzy string search.

Additional details

Tested with Hypothesis v0.51 on Firefox 53, Chrome 57.

robertknight commented 7 years ago

Another and much worse instance of this was reported today by @jeremydean on https://www.nap.edu/read/9853/chapter/3 where the public channel as ~350 annotations. At a quick glance, it looks like many of the orphans might be from other chapters of the same book (?).

Just in case the annotations change in future, I've posted a dump of them at https://gist.github.com/robertknight/108ba6ae921ad567040ac0ef637f94f5

robertknight commented 7 years ago

I've been doing some work on improving how fuzzy string matching works in the dom-anchor-text-quote lib, which could be of use here. This is a profile from the current diff-match-patch based quote anchoring:

bitap-string-match-profile

Here is the profile from a version of dom-anchor-text-quote using a new approx string matching lib:

approx-string-match-profile
lyzadanger commented 4 years ago

I've re-verified that performance on https://www.nap.edu/read/9853/chapter/3 with the current production extension is unacceptable. Once anchoring is complete, the sidebar is responsive and scrolling is smooth, but the anchoring process is painful.

robertknight commented 3 years ago

Fixed by https://github.com/hypothesis/client/pull/2814 (client release >= v1.617.0).