Skip to content

Performance issue with selectCharacters #330

@izhan

Description

@izhan

Hello!

First off, thank you for creating a kickass project :)

I am currently using rangy to analyze sentences (such as grammar, etc) within contenteditables and highlighting the text. Here are my steps:

Every time a user enters text into a contenteditable...

  1. Get the text of a contenteditable from rangy.innerText(el) and analyze it, returning an array of start & end tuples marking which characters should be highlighted
  2. Clear already highlighted elements using range.selectNode(el) and applier.undoToRange(range)
  3. Rehighlighting the text I specify using range.selectCharacters

I noticed that as the number of highlights increase, the performance gets exponentially worse. I ran a Chrome profiler and it seems that the selectCharacters call is the culprit. I dug into the code a bit, and noticed you use caches extensively — could it be one of the caches are no longer being hit?
screen shot 2015-08-19 at 12 02 32 am

If it helps, I've created a JSFiddle! Start typing some text into the contenteditable and you'll see what I mean. https://jsfiddle.net/3zz5pLgx/

1 — Do you know why selectCharacters might have this performance issue?
2 — In general, do you think that my approach to this problem (highlighting characters in text based on start & end values) is correct?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions