DuskSystems / wayfind

A speedy, flexible router for Rust.
Apache License 2.0
8 stars 0 forks source link

Rearchitect router internals. #144

Closed CathalMullan closed 1 month ago

CathalMullan commented 1 month ago

Some work to be done on the performance side of things.

Assuming that due to moving the data out of the node, our cache locality is worse. Plus now we need a hashmap lookup per match.

Instead of a hashmap, we could use a vec + index approach. But would make updates/deletes painful.

We could just change NodeData into an enum?

/// Holds data associated with a given node.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum NodeData<T> {
    /// Data is stored inline.
    Inline(T),

    /// Data is stored at the router level, as it's shared between 2 or more nodes.
    Reference(Arc<str>),
}

EDIT: Yes, much better. Happy to take a 5% hit for this, down from 20%.

We still need to actually disconnect the end-node -> data relationship. Right now, we've just moved it elsewhere.

EDIT: Also, should ensure we use constant terms. I've mixed up path and route multiple times in the docs.

This is only really a 'part 1'. We'll flesh out the finer details as part of the optional params support.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.

:white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/router.rs 73.91% 5 Missing and 1 partial :warning:
Files with missing lines Coverage Δ
src/node/search.rs 78.11% <ø> (ø)
src/router.rs 88.88% <73.91%> (-1.95%) :arrow_down:
codspeed-hq[bot] commented 1 month ago

CodSpeed Performance Report

Merging #144 will degrade performances by 5.39%

Comparing 143-reconsider-router-internal-structure (02687bf) with main (15dd3fe)

Summary

❌ 1 regressions ✅ 15 untouched benchmarks

:warning: Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main 143-reconsider-router-internal-structure Change
path-tree benchmarks/wayfind 66.5 µs 70.2 µs -5.39%