Skip to content
STIMSMITH

Shallow Copy Optimization

Technique WIKI v1 · 5/26/2026

Shallow Copy Optimization is a performance technique in which an object is cloned by allocating a new instance and copying the object's underlying memory slice in one bulk operation. In the cited eUVM implementation, object introspection determines the memory footprint to copy, and the D language slice copy lowers to a single memcopy call, avoiding slower per-field copying associated with UVM utility copy constructs.

Overview

Shallow Copy Optimization is a technique for improving copy performance when a shallow copy is sufficient. In the RISCV-DV context described by the evidence, the generator uses a native shallow-copy construct rather than copying individual elements of a class object through a UVM utilities copy construct.

Implementation pattern

The eUVM implementation follows a low-level clone-and-copy pattern:

  1. Return null if the source object is null.
  2. Obtain the object's ClassInfo through object introspection.
  3. Allocate a new object instance using the discovered class information.
  4. Compute the start and end offsets of the object memory region to be copied.
  5. Copy the source object's memory slice into the destination object's corresponding memory slice.
  6. Return the cloned object cast to the requested type.

The evidence describes this as using object introspection to determine the underlying memory footprint of the object and then copying the corresponding memory slice from source to destination.

Performance rationale

The optimization relies on the fact that, in the D language implementation used by eUVM, the slice-copy operation results in a single memcopy call. This is described as much more efficient than copying individual class-object elements, which would result from using the UVM utilities copy construct.

Applicability

This technique is applicable when a shallow copy is semantically sufficient: the copied object may duplicate the object's immediate stored state, but it does not imply recursive duplication of objects referenced from that state. The evidence specifically states that, for the discussed RISCV-DV use case, a shallow copy suffices and RISCV-DV uses the native shallow-copy construct.

CITATIONS

5 sources
5 citations
[1] RISCV-DV uses a native shallow copy construct when a shallow copy is sufficient. [PDF] Crafting a Million Instructions/Sec RISCV-DV - DVCon Proceedings
[2] The eUVM shallow-copy implementation uses object introspection to determine the memory footprint of the object to be copied. [PDF] Crafting a Million Instructions/Sec RISCV-DV - DVCon Proceedings
[3] The eUVM implementation copies the underlying memory slice from the source object to the destination object. [PDF] Crafting a Million Instructions/Sec RISCV-DV - DVCon Proceedings
[4] In D, the slice-copy operation used for this shallow copy results in a single memcopy call. [PDF] Crafting a Million Instructions/Sec RISCV-DV - DVCon Proceedings
[5] A single memcopy-based slice copy is described as more efficient than copying individual class-object elements through the UVM utils copy construct. [PDF] Crafting a Million Instructions/Sec RISCV-DV - DVCon Proceedings