annulusgames/BurstLinq
关于
Extremely fast LINQ aggregation operations implementation optimized by Burst Compiler
编程语言与运行时实测星标增长
- 24小时
- -1
- 7天
- 0
- 15天
- +2
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文BurstLinq
Extremely fast LINQ aggregation operations implementation optimized by Burst Compiler
Overview
BurstLinq is a library designed to accelerate LINQ aggregation operations (Sum, Average, Min, etc.) using Unity's Burst Compiler. By integrating BurstLinq, automatically optimized implementations are applied to LINQ methods eligible for Burst, resulting in significantly higher performance compared to regular LINQ.
Additionally, BurstLinq adds operators like Sum, Min, etc., to collection types that LINQ cannot usually operate on, such as NativeArray<T> or Span<T>. It also supports operations like Sum and Average for Unity-specific types such as Vector3 and float3.
The concept of BurstLinq is inspired by Cysharp/SimdLinq. BurstLinq is a Unity-optimized version that uses Burst instead of .NET's SIMD API.
Setup
Requirements
- Unity 2021.3 or later
- Burst 1.6.0 or later
Installation
- Open the Package Manager by going to Window > Package Manager.
- Click on the "+" button and select "Add package from git URL".
- Enter the following URL:
https://github.com/AnnulusGames/BurstLinq.git?path=/Assets/BurstLinq
Alternatively, open Packages/manifest.json and add the following to the dependencies block:
{
"dependencies": {
"com.annulusgames.burst-linq": "https://github.com/AnnulusGames/BurstLinq.git?path=/Assets/BurstLinq"
}
}
Quick Start
BurstLinq is designed as a 'Drop-in replacement' similar to SimdLinq, simply including using BurstLinq; will automatically apply BurstLinq methods to all operators eligible for Burst.
using System.Collections.Generic;
using System.Linq;
using BurstLinq;
var enumerable = Enumerable.Range(0, 100);
var array = enumerable.ToArray();
// Enumerable.Sum()
var linqSum = enumerable.Sum();
// BurstLinqExtensions.Sum()
var burstLinqSum = array.Sum();
Supported Types and Operators
Below is the list of operators and types supported by BurstLinq.
Supported Collection Types
T[]List<T>Memory<T>ReadOnlyMemory<T>Span<T>ReadOnlySpan<T>NativeArray<T>NativeList<T>NativeSlice<T>
Supported Operators
- Sum (
int,uint,long,ulong,float,double,Vector2,Vector3,Vector4,int2..4,uint2..4,float2..4,double2..4) - Average (
int,uint,long,ulong,float,double,Vector2,Vector3,Vector4,int2..4,uint2..4,float2..4,double2..4) - Min (
byte,sbyte,short,ushort,int,uint,long,ulong,float,double) - Max (
byte,sbyte,short,ushort,int,uint,long,ulong,float,double) - Contains (
byte,sbyte,short,ushort,int,uint,long,ulong,float,double,Vector2,Vector3,Vector4,int2..4,uint2..4,float2..4,double2..4) - SequenceEqual (
byte,sbyte,short,ushort,int,uint,long,ulong,float,double,Vector2,Vector3,Vector4,int2..4,uint2..4,float2..4,double2..4)
Compatibility with LINQ
BurstLinq may behave differently compared to LINQ as it prioritizes high performance. Be mindful of the following differences when using it.
Sum/Average
While LINQ's Sum is checked, BurstLinq is unchecked. Burst does not support overflow detection, hence it is set to unchecked to avoid behavioral differences when Burst is disabled.
Handling of Floating-Point Types
BurstLinq's Sum specifies [BurstCompile(FloatMode = FloatMode.Fast)], resulting in slight computational discrepancies compared to regular LINQ's Sum. While this is rarely an issue, note the lack of compatibility.
Additionally, BurstLinq does not check for NaN for float/double types, so please take note of this aspect.
License
探索相关项目
加载中…