HomePhabricator
Diffusion Comm 755557751d79

[lib] Introduce RadixTree

Description

[lib] Introduce RadixTree

Summary:
We currently use a rather naive approach for prefix search, where we simply add each substring to a HashMap.

This diff introduces a new data structure optimized for prefix search: the radix tree.

After the improvements in the parent diff, this improve the perf of useChatMentionSearchIndex by 35%. Measuring from before the parent diff, the incremental improvement is about 19%. Combined with the parent diff, in total we're improving perf by 64%.

Linear tasks: ENG-5137 and ENG-5480

Depends on D9625

Test Plan:

  1. Included unit tests
  2. I tested the chat mentions experience
  3. I did some perf testing:

In combination with the following diff, I used this patch to test performance before and after this change. I made sure I had at least three samples of each scenario. Will also link my messy Gist of results, but it's not really interpretable by anyone other than me.

Here's the relevant portion:

BEFORE

 LOG  useChatMentionSearchIndex took 1801ms
 LOG  useChatMentionSearchIndex took 1748ms
 LOG  useChatMentionSearchIndex took 1730ms
 LOG  useChatMentionSearchIndex took 1831ms

 AVERAGE 1777.5ms

JUST DEDUP (parent diff)

 LOG  useChatMentionSearchIndex took 1027ms
 LOG  useChatMentionSearchIndex took 949ms
 LOG  useChatMentionSearchIndex took 957ms

 AVERAGE 977.7ms

DEDUP + RADIX TREE

 LOG  useChatMentionSearchIndex took 643ms
 LOG  useChatMentionSearchIndex took 629ms
 LOG  useChatMentionSearchIndex took 651ms
 LOG  useChatMentionSearchIndex took 609ms

 AVERAGE 633ms

JUST RADIX TREE

 LOG  useChatMentionSearchIndex took 1394ms
 LOG  useChatMentionSearchIndex took 1468ms
 LOG  useChatMentionSearchIndex took 1511ms
 LOG  useChatMentionSearchIndex took 1492ms
 LOG  useChatMentionSearchIndex took 1397ms

 AVERAGE 1452.4ms

Reviewers: tomek, atul, inka, rohan

Reviewed By: tomek

Subscribers: wyilio

Differential Revision: https://phab.comm.dev/D9626

Details

Provenance
ashoatAuthored on Oct 30 2023, 12:02 PM
Reviewer
tomek
Differential Revision
D9626: [lib] Introduce RadixTree
Parents
rCOMM8b569556517a: [CI] run ios/android CI on ios_ci/android_ci branches
Branches
Unknown
Tags
Unknown