Skip to content
Adrian Papari edited this page Oct 3, 2015 · 39 revisions

(DEPRECATED) Weaving off-heap faux structs with @PackedWeaver

Experimental. The current implementation doesn't offer any performance gains over plain or pooled components. Avoid using this feature for now!

At a glance

@PackedWeaver achieves a more memory-friendly layout without introducing any of the boilerplate usually associated with these kind of optimizations.

  • Structs, contiguously in memory.
  • No extra code. Completely transparent.
  • Android support

Application

Even in current day hardware, fetching data from RAM is slow. By using packed components, preemptive caching becomes more efficient, which in theory improves Artemis performance.

Using @PackedWeaver

Component requirements

  • Only primitive types are permitted for fields. No Objects.
  • Zero-argument/default constructor.
  • Must be added to entities Entity#createComponent(Class<Component>), Archetypes or via EntityFactory.
  • Getters/Setters are allowed, but not required.

Your first packed component

Assuming artemis-odb-maven-plugin is properly configured, simply annotate the component with @PackedWeaver:

@PackedWeaver
public class PackedWeaverReference extends Component {
    public float x;
    public float y;

    public void set(Vec2f vec) {
        this.x = vec.x;
        this.y = vec.y;
    }
}

ComponentMapper

For packed components each instance of ComponentMapper#get reuses a flyweight component. To reference more than one component of the same type at the same time create multiple component mappers.

Alternatively, tuck away an extra instance of the component type with ComponentMapper#get(entity, forceNewInstance)

Resources

Clone this wiki locally