-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de2bde9
commit 9ac1813
Showing
32 changed files
with
350 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,75 @@ | ||
# NullGC | ||
|
||
High performance unmanaged memory allocator / collection types / LINQ provider for .NET Core | ||
High performance unmanaged memory allocator / collection types / LINQ provider for .NET Core. | ||
Most suitable for game development since there will be no latency jitter caused by .NET garbage collection activities. | ||
|
||
## Motivation | ||
This project was born mostly out of my curiosity on how far can it go to entirely eliminate garbage collection. Although .NET background GC is already good at hiding GC stops, still there are some. Also for throughput focused scenarios, there may be huge throughput difference when GC is completely out of the equation. | ||
|
||
|
||
## Usage | ||
Currently this project contains 3 components: | ||
1. Unmanaged memory allocator | ||
2. Value type only collections | ||
3. Linq operators | ||
|
||
Two types of memory allocation strategy are supported. | ||
### Arena | ||
```csharp | ||
using (AllocatorContext.BeginAllocationScope()) | ||
{ | ||
var list = new ValueList<T>(); | ||
var dict = new ValueDictionary<T>(); | ||
... | ||
} // all Value* collections are automatically disposed as they go out of scope. | ||
``` | ||
### Explicit lifetime | ||
```csharp | ||
// You can construct a value type collection anywhere(including inside of arena scope) | ||
// using this overload: | ||
var list = new ValueList<T>(AllocatorTypes.DefaultUnscoped); | ||
... | ||
// Anywhere after sometime: | ||
list.Dispose(); | ||
``` | ||
To avoid double-free situations, when these collections are passed by value, Borrow() should be used. After this, all copies of the original collections can be safely disposed without double-free. | ||
```csharp | ||
var list = new ValueList<T>(AllocatorTypes.DefaultUnscoped); | ||
... | ||
// ref passing is not affected. | ||
SomeListRefConsumingMethod(in list); | ||
SomeListRefConsumingMethod(ref list); | ||
// value passing should call Borrow() | ||
SomeListConsumingMethod(list.Borrow()) | ||
``` | ||
### Custom collection types | ||
* ValueArray<T> | ||
* ValueList<T> | ||
* ValueDictionary<TKey, TValue> | ||
* ValueStack<T> | ||
* ValueLinkedList<T> | ||
* ValueFixedSizeDeque<T> (Circular buffer) | ||
* SlidingWindow<T> | ||
* SlidingTimeWindow<T> | ||
|
||
### Linq | ||
**The fastest LINQ provider as of today** (2024.1). <Benchmark here> (Compared with LinqGen/RefLinq/HyperLinq) | ||
|
||
Proper usage is with the built-in value typed collections, but good old IEnumerable<T> is also supported. You can still get some benefit on LINQ operators that need to buffer data such as OrderBy. | ||
The LINQ interface has 3 variations: | ||
```csharp | ||
SomeCollection.LinqValue()... // All types of IEnumerable<T> are supported | ||
SomeCollection.LinqRef()... // Besides built-in value typed collections, only Enumerators that exposes 'ref T Current' are supported (e.g. normal array types) | ||
SomeCollection.LinqPtr()... // Only built-in value typed collections are supported. | ||
``` | ||
|
||
## Things to do | ||
1. More examples. | ||
2. Larger test coverage. | ||
3. More collection types. | ||
4. More LINQ providers and support range. | ||
|
||
## Thanks | ||
Many thanks to Emma Maassen from <https://github.com/Enichan/Arenas> and Angouri from <https://github.com/asc-community/HonkPerf.NET> on inspiring me to this project. | ||
|
||
Details in [THIRD-PARTY-NOTICES.md](https://github.com/fryderykhuang/NullGC/blob/gha-test/THIRD-PARTY-NOTICES.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
### .NET | ||
|
||
License: MIT | ||
<https://github.com/dotnet/runtime/blob/main/LICENSE.TXT> | ||
License: [MIT](https://github.com/dotnet/runtime/blob/main/LICENSE.TXT) | ||
|
||
ValueList/ValueDictionary/ValueQueue is modified from corresponding .NET generic collections. | ||
|
||
### Arenas | ||
### [Arenas](https://github.com/Enichan/Arenas) | ||
|
||
License: MIT | ||
<https://github.com/Enichan/Arenas/blob/main/LICENSE> | ||
License: [MIT](https://github.com/Enichan/Arenas/blob/main/LICENSE) | ||
|
||
The ArenaAllocator class is based on code from this project. | ||
|
||
### HonkPerf.NET | ||
### [HonkPerf.NET](https://github.com/asc-community/HonkPerf.NET) | ||
|
||
License: MIT | ||
<https://github.com/asc-community/HonkPerf.NET/blob/main/LICENSE> | ||
License: [MIT](https://github.com/asc-community/HonkPerf.NET/blob/main/LICENSE) | ||
|
||
The NullGC.Linq project is inspired by this project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/NullGC.Abstractions/Allocators/AllocatorProviderIds.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.ComponentModel; | ||
|
||
namespace NullGC.Allocators; | ||
|
||
public enum AllocatorTypes | ||
{ | ||
[EditorBrowsable(EditorBrowsableState.Advanced)] | ||
Invalid = 0, | ||
Default = 1, | ||
[EditorBrowsable(EditorBrowsableState.Advanced)] | ||
ScopedUserMin = 16, | ||
DefaultUnscoped = -1, | ||
DefaultUncachedUnscoped = -2, | ||
[EditorBrowsable(EditorBrowsableState.Advanced)] | ||
UnscopedUserMax = -16, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.