Skip to content

Commit 591b7e0

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
let RegexMatchCache store only unique hashes of regexes
Summary: `RegexMatchCache` does not need to store full regex strings. It needs only some unique identifier of the regex, and cryptographic hashes are commonly used for this purpose. Reviewed By: mdas7 Differential Revision: D63338698 fbshipit-source-id: af9093b1db4bff2dc30607e7bb31b743ee7510d9
1 parent ede5900 commit 591b7e0

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

fb303/CallbackValuesMap-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void CallbackValuesMap<T>::getKeys(std::vector<std::string>* keys) const {
7777
template <typename T>
7878
void CallbackValuesMap<T>::getRegexKeys(
7979
std::vector<std::string>& keys,
80-
const std::string& regex,
80+
const folly::RegexMatchCache::regex_key_and_view& regex,
8181
const folly::RegexMatchCache::time_point now) const {
8282
detail::cachedFindMatches(keys, callbackMap_, regex, now);
8383
}

fb303/CallbackValuesMap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ class CallbackValuesMap {
5959
/* Returns the keys in the map that matches regex pattern */
6060
void getRegexKeys(std::vector<std::string>& keys, const std::string& regex)
6161
const {
62+
const auto key = folly::RegexMatchCache::regex_key_and_view(regex);
6263
const auto now = folly::RegexMatchCache::clock::now();
63-
getRegexKeys(keys, regex, now);
64+
getRegexKeys(keys, key, now);
6465
}
6566
void getRegexKeys(
6667
std::vector<std::string>& keys,
67-
const std::string& regex,
68+
const folly::RegexMatchCache::regex_key_and_view& regex,
6869
const folly::RegexMatchCache::time_point now) const;
6970

7071
/** Returns the number of keys present in the map */

fb303/ServiceData.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,12 @@ void ServiceData::getRegexCounters(
486486
void ServiceData::getRegexCountersOptimized(
487487
map<string, int64_t>& output,
488488
const string& regex) const {
489+
const auto key = folly::RegexMatchCache::regex_key_and_view(regex);
489490
const auto now = folly::RegexMatchCache::clock::now();
490491
std::vector<std::string> keys;
491-
detail::cachedFindMatches(keys, counters_, regex, now);
492-
quantileMap_.getRegexKeys(keys, regex, now);
493-
dynamicCounters_.getRegexKeys(keys, regex, now);
492+
detail::cachedFindMatches(keys, counters_, key, now);
493+
quantileMap_.getRegexKeys(keys, key, now);
494+
dynamicCounters_.getRegexKeys(keys, key, now);
494495
getSelectedCounters(output, keys);
495496
}
496497

fb303/detail/QuantileStatMap-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void BasicQuantileStatMap<ClockT>::getKeys(
179179
template <typename ClockT>
180180
void BasicQuantileStatMap<ClockT>::getRegexKeys(
181181
std::vector<std::string>& keys,
182-
const std::string& regex,
182+
const folly::RegexMatchCache::regex_key_and_view& regex,
183183
const folly::RegexMatchCache::time_point now) const {
184184
detail::cachedFindMatches(keys, counters_, regex, now);
185185
}

fb303/detail/QuantileStatMap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ class BasicQuantileStatMap {
7878
/* Returns the keys in the map that matches regex pattern */
7979
void getRegexKeys(std::vector<std::string>& keys, const std::string& regex)
8080
const {
81+
const auto key = folly::RegexMatchCache::regex_key_and_view(regex);
8182
const auto now = folly::RegexMatchCache::clock::now();
82-
getRegexKeys(keys, regex, now);
83+
getRegexKeys(keys, key, now);
8384
}
8485
void getRegexKeys(
8586
std::vector<std::string>& keys,
86-
const std::string& regex,
87+
const folly::RegexMatchCache::regex_key_and_view& regex,
8788
const folly::RegexMatchCache::time_point now) const;
8889

8990
size_t getNumKeys() const;

fb303/detail/RegexUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace facebook::fb303::detail {
2323
void cachedFindMatchesCopyUnderSharedLock(
2424
std::vector<std::string>& out,
2525
folly::RegexMatchCache const& cache,
26-
std::string_view const regex,
26+
folly::RegexMatchCacheKeyAndView const& regex,
2727
folly::RegexMatchCache::time_point const now) {
2828
auto const matches = cache.findMatchesUnsafe(regex, now);
2929
folly::grow_capacity_by(out, matches.size());

fb303/detail/RegexUtil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ void cachedClearStrings(Map& map) {
6565
void cachedFindMatchesCopyUnderSharedLock(
6666
std::vector<std::string>& out,
6767
folly::RegexMatchCache const& cache,
68-
std::string_view regex,
68+
folly::RegexMatchCacheKeyAndView const& regex,
6969
folly::RegexMatchCache::time_point now);
7070

7171
template <typename SyncMap>
7272
void cachedFindMatches(
7373
std::vector<std::string>& out,
7474
SyncMap& map,
75-
std::string_view const regex,
75+
folly::RegexMatchCacheKeyAndView const& regex,
7676
folly::RegexMatchCache::time_point const now) {
7777
auto r = map.rlock();
7878
if (!r->matches.isReadyToFindMatches(regex)) {

0 commit comments

Comments
 (0)