xmath-usage

Apply in-place xmath optimizations to Defold math code using pre-allocated scratch buffers.

Updated Apr 16, 2026
One-click install
npx skills add https://github.com/zarkua/Defolancer --skill xmath-usage-zarkua
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: xmath-usage
Source: https://github.com/zarkua/Defolancer/tree/main/.agents/skills/xmath-usage
Command: npx skills add https://github.com/zarkua/Defolancer --skill xmath-usage-zarkua

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

In hot loops, Lua allocations from math operations create GC pressure that hurts frame rates. xmath mutates an existing scratch buffer in place so no new objects are created per frame.

Core Features & Use Cases

  • In-place mutation for vector/quaternion/matrix operations.
  • Pre-allocate scratch variables at module scope or init to avoid allocations inside update().
  • Works with vector3/vector4/quaternion/matrix APIs to reduce garbage collection in performance-critical code.

Quick Start

Pre-allocate scratch variables at module scope and replace per-frame allocations with xmath calls that mutate results in place.

Frequently Asked Questions about xmath-usage

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce Lua GC pressure from math operations in Defold hot loops?

To reduce Lua GC pressure in Defold hot loops, use in-place xmath optimizations that mutate a pre-allocated scratch buffer instead of creating new vector3, vector4, quaternion, or matrix objects per frame.

What is the best way to pre-allocate scratch variables for Defold math calculations?

The best way to pre-allocate scratch variables for Defold math calculations is to define them at module scope or during initialization, then use xmath calls to write results directly into these existing buffers inside update() methods.

How does in-place mutation work with the defold-xmath library?

In-place mutation with the defold-xmath library works by writing all mathematical operation outputs directly into the first argument provided, ensuring no new object allocations are performed during game logic execution.

Can I use xmath optimizations for regular Defold vector3 and quaternion operations?

Yes, you can use xmath optimizations for regular Defold vector3, vector4, quaternion, and matrix operations by replacing standard API calls with xmath equivalents that mutate pre-allocated scratch buffers in place to avoid garbage collection overhead.

Do I need the defold-xmath library to perform zero-allocation math in Defold?

Yes, you need the defold-xmath library, such as thejustinwalsh/defold-xmath, and a pre-allocated scratch buffer to perform zero-allocation math in Defold and eliminate per-frame object creation in hot loops.

When should I avoid using in-place xmath optimizations in Defold game logic?

You should avoid using in-place xmath optimizations in Defold game logic outside of performance-critical hot loops, as the library requires a pre-allocated scratch buffer and mutates the first argument, which is unnecessary overhead for standard math operations not causing GC pressure.