diff options
| author | Brooks Rady <b.j.rady@gmail.com> | 2021-10-26 11:43:17 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 18:43:17 +0100 |
| commit | 6bb1ec6636eac97512eecd4eab6c224aea5b4596 (patch) | |
| tree | 5ae2373237802de31ed42465e954e3c52dc0abc3 /zellij-server/src | |
| parent | docs(changelog): wide char midline fix (diff) | |
| download | sl0ppij-6bb1ec6636eac97512eecd4eab6c224aea5b4596.tar.gz sl0ppij-6bb1ec6636eac97512eecd4eab6c224aea5b4596.tar.xz sl0ppij-6bb1ec6636eac97512eecd4eab6c224aea5b4596.zip | |
fix(perf): plugins are only compiled once
Diffstat (limited to 'zellij-server/src')
| -rw-r--r-- | zellij-server/src/wasm_vm.rs | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/zellij-server/src/wasm_vm.rs b/zellij-server/src/wasm_vm.rs index de42b611..74923d41 100644 --- a/zellij-server/src/wasm_vm.rs +++ b/zellij-server/src/wasm_vm.rs @@ -1,14 +1,23 @@ +use crate::{ + logging_pipe::LoggingPipe, + panes::PaneId, + pty::{ClientOrTabIndex, PtyInstruction}, + screen::ScreenInstruction, + thread_bus::{Bus, ThreadSenders}, +}; +use highway::{HighwayHash, PortableHash}; use log::{debug, info, warn}; -use std::collections::{HashMap, HashSet}; -use std::fs; -use std::path::{Path, PathBuf}; -use std::process; -use std::str::FromStr; -use std::sync::{mpsc::Sender, Arc, Mutex}; -use std::thread; -use std::time::{Duration, Instant}; - use serde::{de::DeserializeOwned, Serialize}; +use std::{ + collections::{HashMap, HashSet}, + fs, + path::{Path, PathBuf}, + process, + str::FromStr, + sync::{mpsc::Sender, Arc, Mutex}, + thread, + time::{Duration, Instant}, +}; use url::Url; use wasmer::{ imports, ChainableNamedResolver, Function, ImportObject, Instance, Module, Store, Value, @@ -16,15 +25,10 @@ use wasmer::{ }; use wasmer_wasi::{Pipe, WasiEnv, WasiState}; use zellij_tile::data::{Event, EventType, PluginIds}; - -use crate::{ - logging_pipe::LoggingPipe, - panes::PaneId, - pty::{ClientOrTabIndex, PtyInstruction}, - screen::ScreenInstruction, - thread_bus::{Bus, ThreadSenders}, +use zellij_utils::{ + consts::ZELLIJ_PROJ_DIR, + errors::{ContextType, PluginContext}, }; -use zellij_utils::errors::{ContextType, PluginContext}; use zellij_utils::{ input::command::TerminalAction, input::layout::RunPlugin, @@ -177,8 +181,22 @@ fn start_plugin( .resolve_wasm_bytes(&data_dir.join("plugins/")) .unwrap_or_else(|| panic!("Cannot resolve wasm bytes for plugin {:?}", plugin)); - // FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that - let module = Module::new(store, &wasm_bytes).unwrap(); + let hash: String = PortableHash::default() + .hash256(&wasm_bytes) + .iter() + .map(ToString::to_string) + .collect(); + + let cached_path = ZELLIJ_PROJ_DIR.cache_dir().join(&hash); + + let module = unsafe { + Module::deserialize_from_file(store, &cached_path).unwrap_or_else(|_| { + let m = Module::new(store, &wasm_bytes).unwrap(); + fs::create_dir_all(ZELLIJ_PROJ_DIR.cache_dir()).unwrap(); + m.serialize_to_file(&cached_path).unwrap(); + m + }) + }; let output = Pipe::new(); let input = Pipe::new(); |
