desconexo / highlight_text

A flutter plugin to highlight words from a text
MIT License
30 stars 22 forks source link

Performance really slow. #51

Closed dev-hann closed 3 months ago

dev-hann commented 1 year ago

I used in ListView about 6-10 item which has a TextHighlight on Web. and restart App just stuck. after change to default text widget, works on..

  return GestureDetector(
      onTap: onTap,
      child: Card(
        clipBehavior: Clip.hardEdge,
        child: Column(
          children: [
            WebImage(
              post.thumbnail,
              width: 700,
              height: 350,
              fit: ObjectFit.cover,
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(post.title), // this part change to TextHightlight
                  Text(
                    DateFormat("yyyy년MM월dd일").format(post.releaseDateTime),
                  ),
                  Row(
                    children: post.tagList.map((e) => Text("#$e ")).toList(),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );

Am i used wrong way?

crizant commented 10 months ago

Since @desconexo has been inactive for some time, I decided to continue to support this package. I have published a new one and let's discuss the issue there: https://pub.dev/packages/highlight_text_plus

oriventi commented 3 months ago

I've submitted a pull request (#54) to address this performance issue.

Root cause analysis: The problem occurs when empty or whitespace-only strings are used as keys for HighlightedWord instances. This leads to excessive creation of MatchedElement items.

Impact: During profiling, I observed the creation of approximately 96 million MatchedElement instances, resulting in significant memory consumption.

Proposed solution: The pull request implements a filtering mechanism at the sorting stage to remove empty or whitespace-only keys before they can impact performance downstream.

Next steps: I kindly request a review of the proposed changes. Any feedback or suggestions for improvement would be greatly appreciated.