One approach is to write the filtering engine from scratch. It is what I did, without looking at ABP's code beforehand in order to ensure a clean slate mind.
I didn't get it right the first time, I did spend quite a large amount of time benchmarking, measuring, prototyping, etc.
Once I was satisfied I had finally had a solid code base, I went and benchmarked it against ABP to find out how it compared:
https://github.com/gorhill/httpswitchboard/wiki/Net-request-...
And for HTTPSB's numbers, keep in mind there were an extra over 50,000 rules in the matrix filtering engine (something not found in ABP).
So I think this shows clearly ABP's code can be improved.