aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-10-23 15:18:10 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-10-23 15:23:52 +0200
commit4425f230e7f3fae010a9316886eab7f960d3669c (patch)
treec2fb502c622c13db9e9a593ee5d30e280c930456 /src/lib.rs
parent6c7e6c73a7bafe4ee90e145e4c067f4658e9a827 (diff)
downloadevtclib-4425f230e7f3fae010a9316886eab7f960d3669c.tar.gz
evtclib-4425f230e7f3fae010a9316886eab7f960d3669c.tar.bz2
evtclib-4425f230e7f3fae010a9316886eab7f960d3669c.zip
speed up agent-by-addr search
When this function was written, it was done under the assumption that a) There are not a lot of agents, so linear search is fast enough and b) We just want it to work for now However, it turns out that there can be a lot of agents, close to 1000 for the Qadim log for example. This means that there is quite some time saving that we can do here, as get_agent_by_addr is used a lot in set_agent_awares and set_agent_masters, so speeding this part up is good! We could build a HashMap, mapping the address to the agent (index), but that would mean that we have to carry the hash map around. This patch provides a simpler yet already good improvement: We invest a bit of time after converting all agents to sort them by their address (as the agent order is implementation defined anyway), so we can later use a binary search to get the right agent. It's not O(1), as a hash map would be, but it works in logarithmic time and already provides a big benefit: Before process Qadim time: [39.444 ms 39.501 ms 39.561 ms] After process Qadim time: [18.699 ms 18.744 ms 18.788 ms] change: [-52.672% -52.546% -52.413%] (p = 0.00 < 0.05) That is half of the processing time saved by a 3 line patch!
Diffstat (limited to 'src/lib.rs')
0 files changed, 0 insertions, 0 deletions