Implement Cache for improving performance of ContentEventHandler

NEW
Assigned to

Status

()

Core
Event Handling
P2
normal
a year ago
2 months ago

People

(Reporter: masayuki, Assigned: masayuki)

Tracking

({inputmethod, perf})

Trunk
inputmethod, perf
Points:
---

Firefox Tracking Flags

(firefox50 affected)

Details

As we know, ContentEventHandler is very slow with big offset in HTML editor.

So, I'm now thinking about how to improve it.

Current my idea is, we should create ContentEventHandler::Cache as a nested class. It has an array whose item is:

class Item final
{
  friend class ContentEventHandler;
  friend class ContentEventHandler::Cache;

private:
  // A node causing text
  nsIContent* mContent;
  // Generated text
  uint32_t mLength;

public:
  nsIContent* Content() const { return mContent; }
  uint32_t Length() const { return mLength; }
};

And the cache class is like:

class Cache final
{
private:
  nsTArray<Item> mItems;

  struct HistoryItem final
  {
    // index of the item
    size_t mIndex;
    // offset of the item
    uint32_t mOffset;
  };
  // When ContentEventHandler computes a offset, the index and offset are
  // stored to mHistory. Then, next query can skip to compute before the
  // computed offset.
  nsTArray<HistoryItem> mHistory;
};

If it's possible to cache this case in IMEContentObserver, we might be able to improve the performance of multiple query content event handlers, but I'm not sure we can do that with enough simple code.

If you have better idea about cache mechanism, let me know.
# I'm thinking that I could work on this in Q4.
Masayuki, are you planning to resume this work soon?
Flags: needinfo?(masayuki)
Priority: -- → P2
I'd like to do that as soon as possible, however, the priority isn't so high in my queue.
Flags: needinfo?(masayuki)
You need to log in before you can comment on or make changes to this bug.