keymanapp / keymanapp/keyman

chore(web): Mock generation can be costly with SMP enabled.

Open
#8,906 0 comments 0 reactions 0 assignees View on GitHub
web/
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.