Ocelot icon indicating copy to clipboard operation
Ocelot copied to clipboard

Use unordered_set for whitelist lookups

Open undertheironbridge opened this issue 5 years ago • 1 comments

All whitelist lookups are currently performed by a linear search over a std::vector of std::string objects. Since peer IDs are always 20 bytes long, an std::array might be better suited for this, and has the added advantage of always storing the data contiguously, which is not a requirement with std::strings. Storing such std::arrays in an unordered_set gives a clear performance advantage, as illustrated in this benchmark.

Since whitelist lookups need to be made for every announce, I suppose this might have a very positive impact on the overall performance of the tracker.

undertheironbridge avatar May 06 '20 23:05 undertheironbridge

It just occurred to me that the database-stored whitelist entries are actually meant to be used as peer_id prefixes, not literal peer_ids to be matched. In this case, this whole PR can really be scrapped, as it won't work as expected. The only thing that can potentially stay is the test script (with appropriate changes), which might come in handy should anyone like to change the whitelisting implementation or perhaps use it as a starting point for testing the tracker as a whole.

undertheironbridge avatar May 13 '20 20:05 undertheironbridge