All Projects → dave-hillier → Disruptor Unity3d

dave-hillier / Disruptor Unity3d

Licence: apache-2.0
Basic implementation of Disruptor for Unity3d

Labels

Projects that are alternatives of or similar to Disruptor Unity3d

Uecs
Ubpa Entity-Component-System (U ECS) in Unity3D-style
Stars: ✭ 174 (-3.33%)
Mutual labels:  unity3d
Unigltf
glTF 2.0 importer and exporter for Unity 5.6 or later
Stars: ✭ 177 (-1.67%)
Mutual labels:  unity3d
Geovfx
Examples of geographical data visualization with Unity VFX Graph
Stars: ✭ 179 (-0.56%)
Mutual labels:  unity3d
Unity Dithered Transparency Shader
Unity material and shader for applying clipped, dithered transparency
Stars: ✭ 174 (-3.33%)
Mutual labels:  unity3d
Bobbin
small Unity editor tool that can automatically download and import Google Docs or Sheets (or anything with a URL) into your Unity project; perfect for collaborating with designers, writers, or translators
Stars: ✭ 176 (-2.22%)
Mutual labels:  unity3d
Headphonemotion
Unity plugin for Apple Headphone Motion API.
Stars: ✭ 178 (-1.11%)
Mutual labels:  unity3d
Threedscans
Scanned statue models from the Three D Scans project, optimized for real-time rendering use.
Stars: ✭ 172 (-4.44%)
Mutual labels:  unity3d
Unitybarcodescanner
Simple Unity Barcode Scanner
Stars: ✭ 180 (+0%)
Mutual labels:  unity3d
Poco Sdk
Stars: ✭ 176 (-2.22%)
Mutual labels:  unity3d
Unityexplorer
An in-game explorer and a suite of debugging tools for IL2CPP and Mono Unity games, to aid with modding development.
Stars: ✭ 172 (-4.44%)
Mutual labels:  unity3d
Shaders
A collection of shaders written in CG/ShaderLab for Unity.
Stars: ✭ 173 (-3.89%)
Mutual labels:  unity3d
Ssrt
Real-time indirect diffuse illuminaton using screen-space information for Unity.
Stars: ✭ 176 (-2.22%)
Mutual labels:  unity3d
Zinnia.unity
A collection of design patterns for solving common problems.
Stars: ✭ 177 (-1.67%)
Mutual labels:  unity3d
Unitydxrtest
A testbed project for Unity real-time ray tracing features
Stars: ✭ 172 (-4.44%)
Mutual labels:  unity3d
Lwrpambientocclusion
Post-Processing Stack v2 Ambient Occlusion works on Lightweight Render Pipeline
Stars: ✭ 179 (-0.56%)
Mutual labels:  unity3d
Nvjob Water Shader Simple And Fast
#NVJOB Simple Water Shaders. Free Unity Asset.
Stars: ✭ 172 (-4.44%)
Mutual labels:  unity3d
Kinovision
Frame visualization utility for Unity
Stars: ✭ 177 (-1.67%)
Mutual labels:  unity3d
Kinobinary
Binary image effect for Unity
Stars: ✭ 180 (+0%)
Mutual labels:  unity3d
Htframework
Unity HTFramework, a rapid development framework of client to the unity.
Stars: ✭ 179 (-0.56%)
Mutual labels:  unity3d
Unity Design Pattern
🍵 All Gang of Four Design Patterns written in Unity C# with many examples. And some Game Programming Patterns written in Unity C#. | 各种设计模式的Unity3D C#版本实现
Stars: ✭ 2,600 (+1344.44%)
Mutual labels:  unity3d

disruptor-unity3d

Basic, self contained, implementation of Disruptor for Unity3d. Only supports a single producer/single consumer. Only tested on x86 platforms. Bugs in Mono prevent this is working on iOS and Android before Unity 5.5.

Usage

Copy RingBuffer.cs into your Unity project's assets folder (or sub-folder) and use the generic RingBuffer class. For example:

  var buffer = new RingBuffer<int>(8);
  for (int i = 1; i < 6; ++i)
    buffer.Enqueue(i);
  for (int i = 1; i < 6; ++i)
    buffer.Dequeue();

Motivation

Unity3d is a game engine with Mono embedded in it. The version of Mono inside Unity is very old; it doesnt have the SGen collector and uses the Boehm GC. The Boehm GC does not have great performance.

When working on a Unity project I've found myself in need of a Queue for sending messages between threads. The current version of Mono contains an implementation of ConcurrentQueue.

My game uses a queue pretty intensively. When I want to send a message, it is enqueued to a queue and then subsequently dequeued by another thread, which serializes and sends it. When profiling, I've seen that the queue seems to be the source of the ocasional slow frame because it allocates with every message that is queued. The allocations can cause GC stalls at any time, but sometimes it doesnt doesnt explicitly appear on the profiler (for example, the profiler will show a long time in allocation itself and a reduction in total memory usage).

I wanted to replace the ConcurrentQueue with something that did not have any extra allocation overhead. A circular buffer is a fixed size data structure that could be used in this case. When searching for an existing implementation I remembered the Disruptor; a high performance lockless queue. Disruptor has many good qualities, but in my case, I only care about the lack of allocations.

There is a .Net port of the Disruptor, but it is for .Net 4 which is not supported by Unity and it actually makes some allocations. I did not want to spend the time porting it and I have a very much simpler use case. I don't need most of the functionality.

I've implemented a very simple, self-contained version that uses the volatile long that is key to the implementation. It is intended to be self contained; just drop the source into your project. This project is not intended to rival the functionality of disruptor-net but provide an easy to use drop in queue. If you need a fully featured disruptor library then you should port or check out the forks incase someone has already done it.

Benchmark

I've created a benchmark in Test.cs for my single producer/single consumer RingBuffer. Each frame a batch of random integers are queued. The values are dequeued and discarded by the other thread.

This benchmark is not intended as an example use case or to take performance, but allowed me to profile for allocations.

Concurrent Queue

Note:

  • the yellow spikes represent time spent on GC.
  • All frames are longer than 5ms some frames are longer than 16ms.

ConcurrentQueue profile

RingBuffer

Note:

  • No yellow GC spikes
  • Most frames are under 5ms, no frames are longer than 16ms.

RingBuffer profile

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].