software-mansion / software-mansion/react-native-enriched-html
[iOS]: anyTextHaveBeenModified performance
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.4k
- Forks
- 66
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 11
Description
Describe the bug
At the moment, when working with a medium-sized text and typing quickly, the caret and text updates can feel noticeably laggy. This appears to be caused by anyTextHaveBeenModified being executed on every text change within the text view. Since this method iterates over the entire input range and processes blockquote and inline code colors, heading styles, and zero-width spaces, it is relatively expensive.
In practice, this results in a performance cost of approximately 25 ms per single character change for an HTML input of around 3k characters, which is not particularly large.
Proposed solution
- It may be worth reconsidering whether color handling is necessary inside textViewDidChange. Similar to the approach used in the foreground color styles PRs, this logic could potentially be handled elsewhere, with base colors restored in the same way if needed.
- Improper headings could likely be resolved in a single pass, rather than running separate logic for each heading style.
- At this point, it is unclear how best to handle zero-width spaces. However, with the new parser and serializer implementation, it may be unlikely for them to appear in the text view at all.
Expected behavior
Typing shouldn't be laggy
Screenshots
If applicable, add screenshots to help explain your problem.
Device (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating anyTextHaveBeenModified and its call from textViewDidChange, then profile typing in a roughly 3k-character HTML input. Review the color, heading, and zero-width-space processing described in the issue; done means character edits no longer cause noticeable caret or text-update lag.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native
- Domain
- mobile, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100