chore(web): Mock generation can be costly with SMP enabled.
- Dominant language
- Pascal
- Stars
- 534
- Forks
- 143
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 113
Description
> Noting that this is very slow when SMP is enabled. Minor performance improvement suggested by @jahorton (for future PR): take raw position of start of selection, end of selection, and text length, then measure the two shortest segments.
_Originally posted by @mcdurdin in https://github.com/keymanapp/keyman/pull/8875#discussion_r1212565738_
Mock generation aims to copy all three segments of the represented context accurately:
- text before the caret
- text after the caret
- selected text
Currently, we calculate the size of 'before' and 'after' to do so, computing 'selected' from the leftovers.
A near-certainly more likely general-use case:
- Long pre-caret context
- No / short selection
- No post-caret context
For such a scenario, it'd be far more efficient to compute the size of the latter two and infer the size of the first instead.
To generalize a bit better... just compute the size of the two smallest sections, then infer the third. That'd be the least costly approach. The heuristic for "smallest sections" - the _raw_ length of the string, not accounting for SMP, which is notably faster.
Contributor guide
Assessment
This issue has not been assessed yet.