Skip to content

Commit

Permalink
Use std::unordered_map<int, int> for StdIntMap.
Browse files Browse the repository at this point in the history
When using `std::map<int, int>`, profiling shows a hotspot in the
iteration in `PrefilterTree::PropagateMatch()`. Application-level
benchmarks indicate that changing maps produces a noticeable win.

Change-Id: I0a7c43de254642b8ccd188cc93eff4d08d3c10fd
Reviewed-on: https://code-review.googlesource.com/c/re2/+/59990
Reviewed-by: Perry Lorier <[email protected]>
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Mar 24, 2022
1 parent 4c7b561 commit 248b65f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion re2/prefilter_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void PrefilterTree::Compile(std::vector<std::string>* atom_vec) {

compiled_ = true;

// TODO(junyer): Use std::unordered_set<Prefilter*> instead?
NodeMap nodes;
AssignUniqueIds(&nodes, atom_vec);

Expand Down
5 changes: 4 additions & 1 deletion re2/prefilter_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <map>
#include <string>
#include <unordered_map>
#include <vector>

#include "util/util.h"
Expand Down Expand Up @@ -59,7 +60,9 @@ class PrefilterTree {

private:
typedef SparseArray<int> IntMap;
typedef std::map<int, int> StdIntMap;
typedef std::unordered_map<int, int> StdIntMap;
// TODO(junyer): Use std::unordered_set<Prefilter*> instead?
// It should be trivial to get rid of the stringification...
typedef std::map<std::string, Prefilter*> NodeMap;

// Each unique node has a corresponding Entry that helps in
Expand Down

0 comments on commit 248b65f

Please sign in to comment.