From 950a84c337f317388cf39a3820125e049c598b8d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2022 14:39:13 +0200 Subject: Optimize header cache some more by storing hash in key --- libbuild2/cc/compile-rule.cxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'libbuild2/cc/compile-rule.cxx') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index 2faa711..c72c94c 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -2906,7 +2906,10 @@ namespace build2 // First check the cache. // - if (fp.absolute ()) + config_module::header_key hk; + + bool e (fp.absolute ()); + if (e) { if (!norm) { @@ -2914,14 +2917,19 @@ namespace build2 norm = true; } + hk.file = move (fp); + hk.hash = hash () (hk.file); + slock l (hc.header_map_mutex); - auto i (hc.header_map.find (fp)); + auto i (hc.header_map.find (hk)); if (i != hc.header_map.end ()) { //cache_hit.fetch_add (1, memory_order_relaxed); return make_pair (i->second, false); } + fp = move (hk.file); + //cache_mis.fetch_add (1, memory_order_relaxed); } @@ -2957,10 +2965,18 @@ namespace build2 // if (r.first != nullptr) { + hk.file = move (fp); + + // Calculate the hash if we haven't yet and re-calculate it if the + // path has changed (header has been remapped). + // + if (!e || r.second) + hk.hash = hash () (hk.file); + const file* f; { ulock l (hc.header_map_mutex); - auto p (hc.header_map.emplace (move (fp), r.first)); + auto p (hc.header_map.emplace (move (hk), r.first)); f = p.second ? nullptr : p.first->second; } -- cgit v1.1