forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1824772: part 4 - Cache jit hints in the process for eager baseli…
…ne compilation r=iain,arai Add a cache, based on a bloom filter, in the JIT Runtime that will exist for the process lifetime. Whenever a script is baseline compiled, we add a hint to the cache based on the script filename+sourceStart values. If we encounter this script again, during a navigation for example, then we can eagerly compile this script and skip the warmup. Using a bloom filter does introduce false positives, so we try to maintain a false positivity rate of less than 1% and if we exceed this value we clear the cache. Depends on D175523 Differential Revision: https://phabricator.services.mozilla.com/D175524
- Loading branch information
Showing
6 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* vim: set ts=8 sts=2 et sw=2 tw=80: | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef jit_JitHints_inl_h | ||
#define jit_JitHints_inl_h | ||
|
||
#include "jit/JitHints.h" | ||
#include "mozilla/HashFunctions.h" | ||
|
||
namespace js::jit { | ||
|
||
inline JitHintsMap::ScriptKey JitHintsMap::getScriptKey( | ||
JSScript* script) const { | ||
if (ScriptKey key = script->filenameHash()) { | ||
return mozilla::AddToHash(key, script->sourceStart()); | ||
} | ||
return 0; | ||
} | ||
|
||
inline void JitHintsMap::incrementEntryCount() { | ||
// Clear the cache if we've exceeded the false positivity rate | ||
// calculated by MaxEntries. | ||
if (++entryCount_ > MaxEntries_) { | ||
map_.clear(); | ||
entryCount_ = 0; | ||
} | ||
} | ||
|
||
inline void JitHintsMap::setEagerBaselineHint(JSScript* script) { | ||
ScriptKey key = getScriptKey(script); | ||
if (!key) { | ||
return; | ||
} | ||
|
||
// If the entry already exists, don't increment entryCount. | ||
if (map_.mightContain(key)) { | ||
return; | ||
} | ||
|
||
// Increment entry count, and possibly clear the cache. | ||
incrementEntryCount(); | ||
|
||
script->setNoEagerBaselineHint(false); | ||
map_.add(key); | ||
} | ||
|
||
inline bool JitHintsMap::mightHaveEagerBaselineHint(JSScript* script) const { | ||
if (ScriptKey key = getScriptKey(script)) { | ||
return map_.mightContain(key); | ||
} | ||
script->setNoEagerBaselineHint(true); | ||
return false; | ||
} | ||
|
||
} // namespace js::jit | ||
|
||
#endif /* jit_JitHints_inl_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* vim: set ts=8 sts=2 et sw=2 tw=80: | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef jit_JitHints_h | ||
#define jit_JitHints_h | ||
|
||
#include "mozilla/BloomFilter.h" | ||
#include "vm/JSScript.h" | ||
|
||
namespace js::jit { | ||
|
||
/* | ||
* The JitHintsMap implements a BitBloomFilter to track whether or not a script, | ||
* identified by filename+sourceStart, has been baseline compiled before in the | ||
* same process. This can occur frequently during navigations. | ||
* | ||
* The bloom filter allows us to have very efficient storage and lookup costs, | ||
* at the expense of occasional false positives. The number of entries added | ||
* to the bloom filter is monitored in order to try and keep the false | ||
* positivity rate below 1%. If the entry count exceeds MaxEntries_, which | ||
* indicates the false positivity rate may exceed 1.5%, then the filter is | ||
* completely cleared to reset the cache. | ||
*/ | ||
|
||
class JitHintsMap { | ||
// ScriptKey is a hash on the filename+sourceStart. | ||
using ScriptKey = HashNumber; | ||
|
||
static constexpr uint32_t CacheSize_ = 16; | ||
mozilla::BitBloomFilter<CacheSize_, ScriptKey> map_; | ||
|
||
/* | ||
* MaxEntries_ is the approximate entry count for which the | ||
* false positivity rate will exceed p=0.015 using k=2 and m=2**CacheSize. | ||
* Formula is as follows: | ||
* MaxEntries_ = floor(m / (-k / ln(1-exp(ln(p) / k)))) | ||
*/ | ||
static constexpr uint32_t MaxEntries_ = 4281; | ||
static_assert(CacheSize_ == 16 && MaxEntries_ == 4281, | ||
"MaxEntries should be recalculated for given CacheSize."); | ||
|
||
uint32_t entryCount_ = 0; | ||
|
||
ScriptKey getScriptKey(JSScript* script) const; | ||
void incrementEntryCount(); | ||
|
||
public: | ||
void setEagerBaselineHint(JSScript* script); | ||
bool mightHaveEagerBaselineHint(JSScript* script) const; | ||
}; | ||
|
||
} // namespace js::jit | ||
#endif /* jit_JitHints_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters