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

translation: avoid unnecessary lookups #1513

Conversation

benoit-pierre
Copy link
Member

@benoit-pierre benoit-pierre commented Mar 26, 2022

Summary of changes

With the following dictionary stacks:

  • user:
{
  "EUPB/EBGS/PEPBS/EUF": "inexpensive",
}
  • commands:
{
  "PHROLG": "{PLOVER:TOGGLE}"
}
  • main:
{
  "A*/KR*/*E/T*/O*/P*/H*/*EU/HR*/*EU/KR*": "acidophilic",
  "OBLG": "okay",
  "-RBGS": "{,}",
  "HRET": "let",
  "AES": "{^'s}",
  "SAOE": "see",
  "HOU": "how",
  "PHAEPB": "many",
  "HRAOUP": "lookup",
  "TP-R": "for",
  "SUFBGS": "suffix",
  "-G": "{^ing}",
  "-S": "{^s}",
  "-D": "{^ed}",
  "-Z": "{^s}",
}

Writing OBLG -RBGS HRET AES SAOE HOU PHAEPB HRAOUP -S TP-R SUFBGSZ, the last stroke results in the following dictionary collection lookups:

# Macros:
/SUFBGSZ in user, main
SUFBGSZ in user, cmds, main
# No suffix:
/-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGSZ
-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGSZ in main
/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGSZ in main
HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGSZ in main
[…]
/SUFBGSZ/SUFBGSZ in user, main
SUFBGSZ/SUFBGSZ in user, main
/SUFBGSZ in user, main
SUFBGSZ in user, cmds, main
# With suffix:
/-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGSZ
-Z in user, cmds, main
/-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGS
-S in user, cmds, main
/-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGZ
-G in user, cmds, main
/-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBSZ
-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGSZ in main
-Z in user, cmds, main
-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGS in main
-S in user, cmds, main
-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBGZ in main
-G in user, cmds, main
-RBGS/HRET/AES/SAOE/HOU/PHAEPB/HRAOUP/-S/TP-R/SUFBGSZ/SUFBSZ in main
[…]
/SUFBGSZ/SUFBSZ in user, main
SUFBGSZ/SUFBGSZ in user, main
-Z in user, cmds, main
SUFBGSZ/SUFBGS in user, main
-S in user, cmds, main
SUFBGSZ/SUFBGZ in user, main
-G in user, cmds, main
SUFBGSZ/SUFBSZ in user, main
/SUFBGSZ in user, main
-Z in user, cmds, main
/SUFBGS in user, main
-S in user, cmds, main
/SUFBGZ in user, main
-G in user, cmds, main
/SUFBSZ in user, main
SUFBGSZ in user, cmds, main
-Z in user, cmds, main
SUFBGS in user, cmds, main

Stats:

  • dictionary collection: 174
  • duplicates : 85 (-Z [21], -G [20], -S [20], …)
  • user : 99
  • commands : 68
  • main : 169
  • dictionaries : 336

This PR cut down on unnecessary / duplicate lookups:

  • Avoid lookups over the longest key limit (prefix stroke).
  • When calling _find_longest_match a second time to account for a possible implicit suffix in the last stroke, don't duplicate lookups for a non-suffix match.
  • Only lookup each possible implicit suffix once (before looking for a longest match).
  • Reuse the results of the initial (macro check) lookups of the last stroke if needed, instead of re-doing them.

Stats with this PR:

  • dictionary collection: 85
  • user : 29
  • commands : 5
  • main : 85
  • dictionaries : 119

Pull Request Checklist

  • Changes have tests
  • News fragment added in news.d. See documentation for details

When calling `_find_longest_match` a second time to account for
a possible implicit suffix in the last stroke, don't duplicate
lookups for a non-suffix match.
Only lookup each possible implicit suffix once.
Reuse the result of the initial (macro check) lookups of the last
stroke if needed, instead of re-doing them.
@benoit-pierre benoit-pierre force-pushed the pr/translation_avoid_unnecessary_lookups branch from c43d819 to 51bf53b Compare March 26, 2022 15:39
@benoit-pierre benoit-pierre merged commit 56f1770 into openstenoproject:master May 14, 2022
@benoit-pierre benoit-pierre deleted the pr/translation_avoid_unnecessary_lookups branch May 14, 2022 22:51
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.

1 participant