The differences in search performance that you notice are that the database uses indexing to search for strings in the database, but in memory you just go through all the records until you find them. In addition, the database stores the hash number for the string and looks for this hash address, which is much faster and does not actually compare strings.
Dictionary<>
also does indexing, but has a delay for adding data when the beginning of the data begins, because when it adds some data, each time it searches where it can be placed at the correct index point.
In addition, the database caches the results, many database caches also index and generate additional statistics that help you quickly find what you are looking for.
It is better to let the database search, unless you can do something faster for additional custom cases.
source share