Skip formatting if data unchanged on Android
Details
This PR skips removing and applying spans on Android if the text, ranges and styles are unchanged to previous run of MarkdownFormatter as span operations are relatively time-consuming on Android.
In particular, this lets us save some time during mounting phase as per systraces below:
Before
After
Related Issues
GH_LINK
Manual Tests
Linked PRs
Note: I feel like there could be some edge-cases where such optimization leads to incorrect result but I wasn't able to find one so far. This needs a bit of thought prior to merging.
@289Adam289 Could you please help me test this PR for regressions? Thanks in advance.
Sure, happy to help. I will get to it soon
BUG: Coping and pasting text on top of exactly the same text formatted range breaks markdown formatting Reproduction steps:
- Write
*world* - Copy exactly
*world* - select
*world* - Paste
https://github.com/user-attachments/assets/96518f2c-705c-4dea-ab8a-0a33a3c35aeb
BUG: Emotes are clipped when toggling text font size.
https://github.com/user-attachments/assets/aa44e0ee-f4b6-41ca-952d-8dfe92cd18a6
I've confirmed that both bug are not reproducible on main and are regressions from this PR I will try to test this PR on E/App tomorrow.
Thanks @289Adam289 for testing out this PR and finding the regressions.
As for https://github.com/Expensify/react-native-live-markdown/pull/568#issuecomment-2536202684, right now I don't have any idea on how to modify the logic to avoid this bug.
Let's keep this PR as draft for now.