Ok now we both made a calculation mistake… it actually would require 512MB or a 448MB when only considering the routable portion of the address space.
So less feasible than I thought. When it would be a bit per /24 subnet it would be the 2MB that I calculated.
However, the advantage of the method is that it does not require “searching”. It only requires indexing and bit testing. That is why it is fast.
For others: the issue with route table lookup is that your route table may contain can contain different routes like this:
0.0.0.0/0 (the default route)
192.168.88.0/24 (the local network route when using MikroTik default config)
192.168.100.0/28 (maybe you have a small space for VPN connections)
etc
To lookup an address in this table you cannot consider the table as one big array where you are looking for a number. You will effectively have to do up to 33 lookups.
First check if a /32 route exists that matches. If not, check if there is a /31 route. If not, check if there is a /30 route.
Etc etc. until you either find a matching route or you end at “check if there is a /0 route” which always matches.
Now of course the data structure for storing the routing table is optimized for fast lookup by dividing it in 33 different structures that each have some form of hashing.
So you walk along those 33 different structures (from a head pointer) and often most of them will be empty (e.g. there is no route with /1 or /2 in your table), so they can be quickly skipped without running expensive hash and compare operations.
But when there are several routes with different subnet sizes, it can still be an “expensive” operation. In my home router there are 272 active routes of many different subnet sizes (32,29,28,27,24,22,16,10,9,8 and 0). But that is not the typical home user situation of course. However, in an internet router there are many many more of them.
The principle of the route cache was that a separate routing table was created with only /32 routes. Every time a lookup in the normal table succeeds, an entry in the cache table was created with the /32 address that was actually looked up, and containing the information from the /nn entry in the normal table where it was found. And some expiry timer.
Now for further routing always this table was searched first. But because it only has /32 routes it does not require the 33 iterations and the lookup will be faster.
Within a single subnet size the route table data structure uses a form of hashing to quickly find a matching entry so it does not have to do a linear search that becomes slower proportionally to the number of items in the cache. My estimation of 5-10 entries was far too low and based on another system that had a small cache that was linearly searched, indeed now I remember that in Linux it was much larger.
Apparently there still were problems with it. Also, I remember that it wasn’t automatically flushed when the routing table was changed, so when you e.g. manually added routes you needed to do a “ip route flush table cache” command or else the cache would return invalid results until its entries timed out by themselves. Probably not convenient when running an automatic routing protocol.
Finally, sometimes in Linux features are changed or dropped because the maintainer or a small committee does not see the value of it. Often they do not consider broader use cases than they have in their own world. This is clearly visible in the optimization of several core parts of the system (e.g. systemd, network manager) towards the use-case of a laptop that has to boot quickly, roam along different fixed and wireless networks that have DHCP, and has only a single active network connection.
Personally I do not care at all how fast the system boots, and I have more use for systems with several network connections, services running only on a part of them, and with a predictable startup order and -synchronization. But I have to live with the constant demolishing of the working solutions for that and replacement with facilities that work in the world of the writer but are inconvenient for me.
The route cache is only a minor example of such changes.