Skip to content

Commit

Permalink
put under feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Feb 25, 2025
1 parent d8c1ef4 commit 764f5f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crates/katana/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ katana-provider.workspace = true
thiserror.workspace = true
tracing.workspace = true

blockifier = { git = "https://github.com/dojoengine/sequencer", rev = "1010caec", features = [ "cairo_native", "testing" ], optional = true }
blockifier = { git = "https://github.com/dojoengine/sequencer", rev = "1010caec", features = [ "testing" ], optional = true }
cairo-native = "0.2.4"
parking_lot = { workspace = true, optional = true }
quick_cache = "0.6.10"
Expand Down Expand Up @@ -48,6 +48,7 @@ blockifier = [
"dep:parking_lot",
"dep:starknet",
]
cairo-native = [ "blockifier/cairo_native" ]
default = [ "blockifier" ]

[[bench]]
Expand Down
16 changes: 15 additions & 1 deletion crates/katana/executor/src/implementation/blockifier/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub static COMPILED_CLASS_CACHE: LazyLock<ClassCache> =

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[cfg(feature = "cairo-native")]
#[error(transparent)]
FailedToCreateThreadPool(#[from] rayon::ThreadPoolBuildError),
}
Expand All @@ -31,6 +32,7 @@ pub struct ClassCache {

#[derive(Debug)]
struct Inner {
#[cfg(feature = "cairo-native")]
pool: rayon::ThreadPool,
cache: Cache<ClassHash, RunnableCompiledClass>,
}
Expand All @@ -40,12 +42,19 @@ impl ClassCache {
const CACHE_SIZE: usize = 100;
let cache = Cache::new(CACHE_SIZE);

#[cfg(feature = "cairo-native")]
let pool = ThreadPoolBuilder::new()
.num_threads(3)
.thread_name(|i| format!("cache-native-compiler-{i}"))
.build()?;

Ok(Self { inner: Arc::new(Inner { cache, pool }) })
Ok(Self {
inner: Arc::new(Inner {
cache,
#[cfg(feature = "cairo-native")]
pool,
}),
})
}

pub fn get(&self, hash: &ClassHash) -> Option<RunnableCompiledClass> {
Expand All @@ -62,7 +71,9 @@ impl ClassCache {
}

ContractClass::Class(ref sierra) => {
#[cfg(feature = "cairo-native")]
let program = sierra.extract_sierra_program().unwrap();
#[cfg(feature = "cairo-native")]
let entry_points = sierra.entry_points_by_type.clone();

let CompiledClass::Class(casm) = class.compile().unwrap() else {
Expand All @@ -72,9 +83,12 @@ impl ClassCache {
let version = SierraVersion::from_str(&casm.compiler_version).unwrap();
let compiled = CompiledClassV1::try_from((casm, version)).unwrap();

#[cfg(feature = "cairo-native")]
let inner = self.inner.clone();
#[cfg(feature = "cairo-native")]
let compiled_clone = compiled.clone();

#[cfg(feature = "cairo-native")]
self.inner.pool.spawn(move || {
trace!(target: "class_cache", class = format!("{hash:#x}"), "Compiling native class");

Expand Down

0 comments on commit 764f5f9

Please sign in to comment.