perf: apply Burst compiler to primary hot-path candidates #34
No reviewers
Labels
No labels
architecture
bug
duplicate
enhancement
help wanted
invalid
performance
quality
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lavarius/ProjectOverlay!34
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/burst-compiler-optimization"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Applies Unity Burst compiler to the three primary per-frame hot paths identified in the analysis. All three use the
[BurstCompile]static-method pattern (same as the existingBurstBlendshapeRemapper) so there is zero job-scheduler overhead — Burst JIT-compiles the methods to SIMD native code and they are called directly from managed code.Changes
SimpleGravity.csGravityMathstatic[BurstCompile]classComputeVelocity()handles the grounded snap (-2f) and gravity accumulation (+= gravity * dt) in native code, including the branchMovementManager.csBurstMovementMathstatic[BurstCompile]class with 3 methods:ComputeCameraRelativeDirection— flattens camera forward/right to XZ plane, normalizes, produces camera-relativefloat3move directionComputeSpeed— dot-product same-direction check → acceleration or decelerationComputeRotation—quaternion.LookRotationSafe+math.slerpreplacing the managedQuaternion.LookRotation+Quaternion.SlerpFaceTracker.csThree improvements stacked:
Start()viaInitBlendshapeCache(), eliminating 52GetBlendShapeIndexstring lookups every frameBlendshapeSmoothingJob[BurstCompile]IJob— 52-float vectorizedmath.lerppass, auto-vectorized by Burst with SIMDApplyBlendshapes()rewritten as a 3-phase batch: read all 52 weights →job.Run()(synchronous Burst, no scheduler) → write all 52 smoothed+remapped weights backOnDestroy()added to safely dispose the four persistentNativeArray<float>buffersExpected Gains
MovementManagerSimpleGravityFaceTrackerNotes
job.Run()is used (notjob.Schedule()) so there is no 1-frame latency and no dependency management neededNativeArraybuffers useAllocator.Persistentto avoid per-frame allocation costquaternion.LookRotationSafeis used instead ofLookRotationto handle zero-length vectors gracefullySimpleGravity.cs: - Add GravityMath [BurstCompile] static class - ComputeVelocity() handles grounded reset (-2f) and gravity accumulation in native code; same pattern as BurstBlendshapeRemapper MovementManager.cs: - Add BurstMovementMath [BurstCompile] static class with 3 methods: - ComputeCameraRelativeDirection: flatten+normalize cam vectors, produce camera-relative float3 moveDir - ComputeSpeed: dot-product direction check + accel/decel logic - ComputeRotation: quaternion.LookRotationSafe + math.slerp - All called synchronously (no job-scheduling overhead); Burst still JIT-compiles to SIMD native code FaceTracker.cs: - Cache all 52 blendshape mesh indices + smooth speeds at Start() to eliminate per-frame GetBlendShapeIndex string/dict lookups - Add persistent NativeArray<float> buffers (Allocator.Persistent) - Add BlendshapeSmoothingJob [BurstCompile] IJob: 52-value vectorized lerp pass executed via job.Run() (main-thread Burst, no scheduler) - Rewrite ApplyBlendshapes() as 3-phase batch: read → Burst smooth → write - Add OnDestroy() to dispose NativeArrays safely Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>