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

Improve removing spans on Android #537

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tomekzaw
Copy link
Collaborator

@tomekzaw tomekzaw commented Nov 5, 2024

Details

This PR changes the way how spans are removed before applying new formatting.

Previously, we would call ssb.getSpans(0, ssb.length(), MarkdownSpan.class) to find all span added in the previous run. All added spans implement MarkdownSpan interface.

After this change, each time we add a span, we add it to mMarkdownSpans list (ArrayList). Then, we iterate over that list to remove all previously added spans and clear the list afterwards.

Related Issues

GH_LINK

Manual Tests

Linked PRs

@tomekzaw tomekzaw requested a review from j-piasecki November 5, 2024 17:53
j-piasecki
j-piasecki previously approved these changes Nov 6, 2024
Copy link
Collaborator

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good but what's the reasoning behind this change?

@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 6, 2024

There's no particular reason for this change right now. Android spans are known to be slow and I want to see if we can make it faster by eliminating ssb.getSpan call in favor of keeping a list of spans.

@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 21, 2024

I've tested out this change on Google Pixel 4 in release mode with profiler attached and removeSpans takes 1.09 ms vs. 1.12 ms. In debug mode, removeSpans takes ~3ms.

So there's no rush to get this PR merged as the performance is comparable.

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.

2 participants