Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IP search; check end character #14

Closed
wants to merge 2 commits into from
Closed

Improve IP search; check end character #14

wants to merge 2 commits into from

Conversation

spacedingo
Copy link

In a LAN with clients 192.x.x.1-255, comparing first character (1) will perform strcmp 254 times for say 192.x.x.14. By checking last character, it would do strcmp 26 times. In the black-hole, less is more : )
Please feel free to change anything and everything - I'm a newbie.

In a LAN with clients 192.x.x.1-255, comparing first character (1) will perform **strcmp** 254 times for say 192.x.x.14.  By checking last character, it would do **strcmp** for (max) 26 times. In the black-hole, less is more : )
Please feel free to change anything and everything - I'm a newbie.
Improve IP search; check end character
@DL6ER
Copy link
Member

DL6ER commented Apr 5, 2017

The whole idea of comparing the first character was born for the domain comparison. Comparing the very first character can be done extremely fast (direct memory access) and does not require a call to any sophisticated string function. Hence, it can speed up the searching for a suitable domain by up to a factor of 36x.
The situation for which I implemented this was for extreme environments like out testing Pi-hole where the domain struct has > 100,000 entries (wich more than 200 million queries in FTL's memory). With this huge amount of domain entries, searching through the whole list with calling strcmp() on each entry is quite slow. Comparing the very first character is very fast.
This was never thought to be added to the clients list which should always be anyhow much smaller than this number. I only added this for the client search as well so that both functions are similar in nature.

I tested your suggestion in this extreme testing environment (for the domains array, because we have only one client there) and interestingly, it seems like it does not change anything in terms of run time. Further investigations seem to suggest that strcmp() is not much more expensive than strlen() and for domains/clients where both the first and the last letter are equal (which can happen like almost always with domain endings like .com), actually both functions have to be called to identify matches. Accordingly, I saw an increase of run time of nearly 30% for the domain finding algorithm.

Hence, I'm going to reject this pull request, because

  • the domain searching gets noticeably slower, and
  • the client searching never needed an algorithmic speed up.

I hope you understand this decision and we look forward to further contributions from you. Rest assured that I know how disappointing it can be if the first contribution to some project gets rejected, but this decision is only motivated by the two points listed above. Although your idea was good in its nature, it revealed to have adverse effects on FTL's performance.

@DL6ER DL6ER closed this Apr 5, 2017
DL6ER pushed a commit that referenced this pull request Oct 14, 2019
Refactor the list module into a List enum
@jens1205 jens1205 mentioned this pull request Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants