Do not cache "one-hit wonders"
This commit is contained in:
@@ -257,8 +257,9 @@ impl Engine {
|
||||
let hash = combine_hashes(hashes.native, hash);
|
||||
|
||||
let cache = caches.fn_resolution_cache_mut();
|
||||
let local_entry: CallableFunction;
|
||||
|
||||
let func = match cache.entry(hash) {
|
||||
let func = match cache.map.entry(hash) {
|
||||
Entry::Vacant(entry) => {
|
||||
let func = if args.len() == 2 {
|
||||
get_builtin_binary_op_fn(name, operands[0], operands[1])
|
||||
@@ -267,14 +268,22 @@ impl Engine {
|
||||
};
|
||||
|
||||
if let Some(f) = func {
|
||||
&entry
|
||||
.insert(Some(FnResolutionCacheEntry {
|
||||
func: CallableFunction::from_fn_builtin(f),
|
||||
source: None,
|
||||
}))
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.func
|
||||
if cache.filter.is_absent(hash) {
|
||||
// Do not cache "one-hit wonders"
|
||||
cache.filter.mark(hash);
|
||||
local_entry = CallableFunction::from_fn_builtin(f);
|
||||
&local_entry
|
||||
} else {
|
||||
// Cache repeated calls
|
||||
&entry
|
||||
.insert(Some(FnResolutionCacheEntry {
|
||||
func: CallableFunction::from_fn_builtin(f),
|
||||
source: None,
|
||||
}))
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.func
|
||||
}
|
||||
} else {
|
||||
let result = self.exec_fn_call(
|
||||
None, global, caches, lib, name, *hashes, operands, false, false, pos,
|
||||
|
Reference in New Issue
Block a user