summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <[email protected]>2024-06-07 17:59:59 -0400
committer<[email protected]>2024-06-07 21:59:59 +0000
commit0d91887c6aa740d3226407cafa1f27c62fd119f4 ()
treecd939cbe7442253b943a425ac3c853826e500ad0
parent425e630ce73cf79fa5529df199dde47fc109a5de (diff)
YJIT: implement cache for recently encoded/decoded contexts (#10938)
* YJIT: implement cache for recently encoded/decoded contexts * Increase cache size to 512
-rw-r--r--yjit/src/core.rs73
1 files changed, 51 insertions, 22 deletions
@@ -15,12 +15,14 @@ use crate::utils::*;
use crate::disasm::*;
use core::ffi::c_void;
use std::cell::*;
-use std::collections::HashSet;
use std::fmt;
use std::mem;
use std::mem::transmute;
use std::ops::Range;
use std::rc::Rc;
use mem::MaybeUninit;
use std::ptr;
use ptr::NonNull;
@@ -839,10 +841,12 @@ enum CtxOp {
EndOfCode,
}
-// Cache of the last context encoded
// Empirically this saves a few percent of memory
// We can experiment with varying the size of this cache
-static mut LAST_CTX_ENCODED: Option<(Context, u32)> = None;
impl Context {
pub fn encode(&self) -> u32 {
@@ -852,20 +856,8 @@ impl Context {
return 0;
}
- /*
- // If this context was previously decoded and was not changed since
- if self.decoded_from != 0 && Self::decode(self.decoded_from) == *self {
- return self.decoded_from;
- }
- */
-
- // If this context was recently encoded (cache check)
- unsafe {
- if let Some((ctx, idx)) = LAST_CTX_ENCODED {
- if ctx == *self {
- return idx;
- }
- }
}
let context_data = CodegenGlobals::get_context_data();
@@ -878,9 +870,7 @@ impl Context {
let idx = self.encode_into(context_data);
let idx: u32 = idx.try_into().unwrap();
- unsafe {
- LAST_CTX_ENCODED = Some((*self, idx));
- }
// In debug mode, check that the round-trip decoding always matches
debug_assert!(Self::decode(idx) == *self);
@@ -896,12 +886,51 @@ impl Context {
let context_data = CodegenGlobals::get_context_data();
let ctx = Self::decode_from(context_data, start_idx as usize);
- // Keep track of the fact that this context was previously encoded
- //ctx.decoded_from = start_idx;
ctx
}
// Encode into a compressed context representation in a bit vector
fn encode_into(&self, bits: &mut BitVector) -> usize {
let start_idx = bits.num_bits();