cloudflare / mitmengine

A MITM (monster-in-the-middle) detection tool. Used to build MALCOLM:
https://malcolm.cloudflare.com
BSD 3-Clause "New" or "Revised" License
799 stars 68 forks source link

optimize using slices #9

Closed gabbifish closed 5 years ago

gabbifish commented 5 years ago

This PR replaces the map-based implementation of db.go with a slice-based implementation. Because iterating over key-value pairs in a map is slower than iterating over a slice, this PR should offer some modest performance speedups.

gabbifish commented 5 years ago

Yes, thank you for documenting this! I realized the ids were equivalent to the insertion order of records, so I thought that it modifying the map implementation to a slice implementation would roughly preserve id logic. One place where that is NOT preserved is in the db Merge() function; ids (indices) are re-mapped to different records. I think this set of changes is fine, but I do understand that this changes how the db is interpreted; in fact, the db is more a record list than anything else now (given explicit ids are no longer used). I'm happy to chance the semantics (e.g. refer to ids as indices instead) if that makes sense.

lukevalenta commented 5 years ago

Sounds good! Changing the id to idx or something is probably a good idea, but not urgent :). I just added it as an issue.