airbnb / DeepLinkDispatch

A simple, annotation-based library for making deep link handling better on Android
http://nerds.airbnb.com/deeplinkdispatch/
4.37k stars 407 forks source link

New Indexed search for Deeplink Match #268

Closed rossbacher closed 4 years ago

rossbacher commented 4 years ago

This update the processor to get rid of Regex and instead generate a byte array from the the list of to be handled deeplinks at compile time and use that byte array during runtime to to the lookup.

Internal tests have shown that this is about 2 orders of magnitudes faster than the current approach and also requires a fraction of the code size currently required (in our test case the amount of code executed (via trace file) went from ~70MB to under 700kb.

To achieve this we encode all supported URLs for a given module into a tree data structure but use url segments instead of characters. This in turn is then encoded into a byte array in the following format:

 1 byte  2 bytes       4 bytes                     2 bytes       n bytes       n bytes
+------+-------------+---------------------------+-------------+-------------+--------------------------------------------------------------------------------------------------------+
|      |             |                           |             |             |                                                                                                        |
| Type |Value length | Children length           | Match idx   | Value       | Children                                                                                               |
|      |             |                           |             |             |                                                                                                        |
+------+-------------+---------------------------+-------------+-------------+--------------------------------------------------------------------------------------------------------+

<----------------------+  9 byte header  +--------------------->             +------+-------------+---------------------------+-------------+-------------+---------------------------+
                                                                             |      |             |                           |             |             |                           |
                                                                             | Type |Value length | Children length           | Match idx   | Value       | Children                  |
                                                                             |      |             |                           |             |             |                           |
                                                                             +------+-------------+---------------------------+-------------+-------------+---------------------------+

The benefit is that we can with very cheap compare operations walk this byte array and do a lookup without having to generate an actual data structure, which would slow down init time. As this usually runs at app start (app started via deep link) this would slow down overall execution time.