MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / compile_with_cache

Method compile_with_cache

cranelift/codegen/src/incremental_cache.rs:39–96  ·  view source on GitHub ↗

Compile the function, as in `compile`, but tries to reuse compiled artifacts from former compilations using the provided cache store.

(
        &mut self,
        isa: &dyn TargetIsa,
        cache_store: &mut dyn CacheKvStore,
        ctrl_plane: &mut ControlPlane,
    )

Source from the content-addressed store, hash-verified

37 /// Compile the function, as in `compile`, but tries to reuse compiled artifacts from former
38 /// compilations using the provided cache store.
39 pub fn compile_with_cache(
40 &mut self,
41 isa: &dyn TargetIsa,
42 cache_store: &mut dyn CacheKvStore,
43 ctrl_plane: &mut ControlPlane,
44 ) -> CompileResult<'_, (&CompiledCode, bool)> {
45 let cache_key_hash = {
46 let _tt = timing::try_incremental_cache();
47
48 let cache_key_hash = compute_cache_key(isa, &self.func);
49
50 if let Some(blob) = cache_store.get(&cache_key_hash.0) {
51 match try_finish_recompile(&self.func, &blob) {
52 Ok(compiled_code) => {
53 let info = compiled_code.code_info();
54
55 if isa.flags().enable_incremental_compilation_cache_checks() {
56 let actual_result = self.compile(isa, ctrl_plane)?;
57 assert_eq!(*actual_result, compiled_code);
58 assert_eq!(actual_result.code_info(), info);
59 // no need to set `compiled_code` here, it's set by `compile()`.
60 return Ok((actual_result, true));
61 }
62
63 let compiled_code = self.compiled_code.insert(compiled_code);
64 return Ok((compiled_code, true));
65 }
66 Err(err) => {
67 trace!("error when finishing recompilation: {err}");
68 }
69 }
70 }
71
72 cache_key_hash
73 };
74
75 let stencil = self
76 .compile_stencil(isa, ctrl_plane)
77 .map_err(|err| CompileError {
78 inner: err,
79 func: &self.func,
80 })?;
81
82 let stencil = {
83 let _tt = timing::store_incremental_cache();
84 let (stencil, res) = serialize_compiled(stencil);
85 if let Ok(blob) = res {
86 cache_store.insert(&cache_key_hash.0, blob);
87 }
88 stencil
89 };
90
91 let compiled_code = self
92 .compiled_code
93 .insert(stencil.apply_params(&self.func.params));
94
95 Ok((compiled_code, false))
96 }

Callers 1

compile_maybe_cachedFunction · 0.80

Calls 11

compute_cache_keyFunction · 0.85
try_finish_recompileFunction · 0.85
OkFunction · 0.85
serialize_compiledFunction · 0.85
code_infoMethod · 0.80
compile_stencilMethod · 0.80
apply_paramsMethod · 0.80
getMethod · 0.45
flagsMethod · 0.45
compileMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected