Repository: nexus-xyz/nexus-zkvm
File: vm/src/emulator/executor.rs (Rust)

Code before:
    ///
    /// This function performs the following steps:
    /// 1. Checks if a basic block containing the current PC is already in the cache.
    /// 2. If cached, returns the existing block.
    /// 3. If not cached, decodes a new block, caches it, and returns it.
    ///
    /// # Returns
    /// if success, return a `BasicBlockEntry` starting at the current PC.
    fn fetch_block(&mut self, pc: u32) -> Result<Rc<BasicBlockEntry>> {
        if let Some(start) = self.executor.basic_block_ref_cache.get(&pc) {
            return Ok(self.executor.basic_block_cache.get(start).unwrap().clone());
        }

        let block = decode_until_end_of_a_block(self.memory.segment_words(
            self.instruction_index,
            pc,
            None,
        )?);
        if block.is_empty() {
            Err(VMErrorKind::VMOutOfInstructions)?
        }

        let entry = Rc::new(BasicBlockEntry::new(pc, block));
        let _ = self.executor.basic_block_cache.insert(pc, entry.clone());

        self.executor
            .basic_block_ref_cache
            .insert(entry.start..entry.end, pc);

        Ok(entry)
    }

    fn get_executor(&self) -> &Executor {
        &self.executor
    }

    fn get_executor_mut(&mut self) -> &mut Executor {
        &mut self.executor
    }

    /// Return a `View` capturing the end-state of the emulator.
    fn finalize(&self) -> View {
        let mut exit_code: Vec<PublicOutputEntry> = Vec::new();
        let mut output_memory: Vec<PublicOutputEntry> = Vec::new();

        if let Some(output_index) = self.public_output_index {
            if let Ok(bytes) = self.memory.segment_bytes(
                output_index,
                self.memory_layout.exit_code(),
                Some(self.memory_layout.public_output_end()),
            ) {

Review comment (performance):
It's not clear to me that this change will help performance? Can you explain why? 
I think the target is to remove the `.clone()` at line 1085 through interior mutability. 

Code after:
    }

    /// Fetches or decodes a basic block starting from the current PC.
    ///
    /// This function performs the following steps:
    /// 1. Checks if a basic block containing the current PC is already in the cache.
    /// 2. If cached, returns the existing block.
    /// 3. If not cached, decodes a new block, caches it, and returns it.
    ///
    /// # Returns
    /// if success, return a `BasicBlockEntry` starting at the current PC.
    fn fetch_block(&mut self, pc: u32) -> Result<Rc<BasicBlockEntry>> {
        if let Some(start) = self.executor.basic_block_ref_cache.get(&pc) {
            return Ok(self.executor.basic_block_cache.get(start).unwrap().clone());
        }

        let block = decode_until_end_of_a_block(self.memory.segment_words(
            self.instruction_index,
            pc,
            None,
        )?);
        if block.is_empty() {
            Err(VMErrorKind::VMOutOfInstructions)?
        }

        let entry = Rc::new(BasicBlockEntry::new(pc, block));
        let _ = self.executor.basic_block_cache.insert(pc, entry.clone());

        self.executor
            .basic_block_ref_cache
            .insert(entry.start..entry.end, pc);

        Ok(entry)
    }

    fn get_executor(&self) -> &Executor {
        &self.executor
    }

    fn get_executor_mut(&mut self) -> &mut Executor {
        &mut self.executor
    }

    /// Return a `View` capturing the end-state of the emulator.
    fn finalize(&self) -> View {
        let mut exit_code: Vec<PublicOutputEntry> = Vec::new();
        let mut output_memory: Vec<PublicOutputEntry> = Vec::new();

        if let Some(output_index) = self.public_output_index {
            if let Ok(bytes) = self.memory.segment_bytes(
                output_index,