Commit Graph

46 Commits

Author SHA1 Message Date
8edb04263f Fixed bug in ImageResultFloat
Added scoped to in TKey key
2026-03-15 17:22:22 +09:00
21e755a56e Added UnsafeMultiHashMap 2026-03-08 15:38:37 +09:00
37d548085e Refactor job API: add JobExecutionContext, update tests
Major breaking change: job interfaces now use JobExecutionContext
instead of threadIndex, enabling thread-aware and dynamic job
dispatching. Updated all job system, SPMD, and test code to match.
Collections improved with new methods and clearer enumerators.
Renamed IJobScheduler.WaitComplete to Wait. Incremented project
versions. Includes bug fixes, documentation, and style updates.
2026-03-04 11:43:39 +09:00
7367826978 Update Job 2026-02-21 17:20:51 +09:00
4f964b2d2a Add Vector type in SPMD to total of load vector size * lane width of number into memory for simd calculation. 2026-02-13 21:47:05 +09:00
75d33d0763 Add Vector3<TLane, TNumber> 2026-02-13 12:51:22 +09:00
f9cb909841 Update math library 2026-02-12 19:43:04 +09:00
a9c143c2a2 SPMD SIMD math library & lock-free job system integration
- Add new SPMD SIMD math project with scalar/vector lanes
- Integrate SPMD jobs and scheduling into job system
- Implement lock-free job dependency management
- Update math functions for .NET 10 and SIMD performance
- Add SPMD benchmarks, compress-store tests, and race tests
- Introduce generic Result<T> error handling utilities
- Solution/project file updates and code cleanup
2026-02-11 22:44:30 +09:00
c36405645b Improve performance and safety 2026-02-01 01:56:17 +09:00
1fee890329 Refactor core APIs, fix bugs, and improve safety
- Make image result/info structs readonly; improve error handling and memory safety in image library
- Introduce IJobScheduler interface; move job scheduling docs to interface
- Remove "index 0 invalid" convention from slot/sparse maps; fix Count logic
- Add Owner<T> for disposable value types in low-level utilities
- Improve ObjectPool<T> thread safety and logic
- Change List<T>.RemoveAndSwapBack to return bool
- Remove unsafe methods from generated math types; add debug range checks
- Update benchmarks and enable collection checks in tests
- Improve documentation, comments, and error messages
- Bump assembly versions across all projects
2025-12-21 16:08:10 +09:00
a1ad0bd2da Improve vector and matrix performance and add swizzle support to .net build-int VectorX type. 2025-12-17 16:55:28 +09:00
a5df2c9637 Add SparseSet Test 2025-12-13 19:29:03 +09:00
5184363e7d Fixed the bug that UnsafeSlotMap return wrong generation after resize. 2025-12-12 16:35:04 +09:00
fb31fd8ca8 Reserve index 0 in SlotMap, improve unsafe collections
- Reserve index 0 as always invalid in SlotMap, ConcurrentSlotMap, UnsafeSlotMap, and UnsafeSparseSet; update all index checks and slot operations accordingly
- Refactor SlotMap to use parallel arrays and BitArray for occupancy
- Double capacity on resize for all major unsafe collections
- Add debugger display support for unsafe collections
- Improve NuGet publishing workflow to skip existing versions
- Increment package versions (LowLevel: 1.3.1, main: 1.0.2)
- Add comprehensive unit tests for SlotMap and ConcurrentSlotMap
- Update main program and documentation for new slot map behavior
2025-12-12 16:10:49 +09:00
f3b0f295a8 Added new TempJobAllocator
Added new AllocationHandle property in Stack.Scope.

Changed the ref AllocationHandle constructor parameter to AllocationHandle on of all UnsafeCollection types
Removed Allocator.Stack. Use Stack.Scope.AllocationHandle to allocate on stack instead.
2025-12-06 22:16:39 +09:00
8f4a2aa5d6 Update DebugSymbols 2025-11-27 15:03:05 +09:00
b67569aa14 Improve AsSpan, CopyTo, and CopyFrom for IUnsafeCollection 2025-11-27 14:04:46 +09:00
3269244ab1 Refactor memory management with MemoryHandle
Replaced `SafeHandle` with a new `MemoryHandle` system for improved memory tracking, safety, and leak detection. Updated allocators (`ArenaAllocator`, `HeapAllocator`, `StackAllocator`) and collections (`UnTypedArray`, `UnsafeArray<T>`, `UnsafeBitSet`) to use `MemoryHandle`.

Refactored `AllocationManager` to use `ConcurrentSlotMap` for live allocation tracking and added methods for managing `MemoryHandle` instances. Simplified alignment and padding logic across allocators and collections.

Enhanced performance with optimized memory operations (`MemClear`, `MemSet`, `MemCpy`) and vectorized operations in `MemoryUtility` and `UnsafeBitSet`. Fixed alignment issues in vectorized memory operations.

Updated tests to reflect the new memory management system and added new tests for `UnsafeBitSet` bitwise operations. Enabled `ENABLE_COLLECTION_CHECKS` for debug builds and improved error messages and documentation.

Removed unused `SafeHandle` code and adjusted project configuration to include necessary references.
2025-11-25 12:27:10 +09:00
27dfa67784 Add Roslyn analyzer and code fix for unique ownership
Some checks failed
Publish NuGet Packages / publish (pull_request) Has been cancelled
Introduce a Roslyn analyzer to enforce unique ownership semantics for structs marked with the `[NonCopyable]` attribute. Added a corresponding code fix to resolve violations by suggesting the use of `Share()` or other ownership transfer methods.

Key changes:
- Added `StructCopyCodeAnalyzer` to detect invalid struct copies.
- Implemented `StructCopyCodeFixProvider` to provide code fixes.
- Created `Misaki.HighPerformance.Analyzer` and `CodeFixes` projects.
- Added unit tests for the analyzer and code fixes.
- Introduced `UniquePtr<T>` and `SharedPtr<T>` for pointer ownership.
- Added a Visual Studio extension project and packaging support.
- Updated `UnsafeUtility` to use `nint`/`nuint` for indices.
2025-11-22 18:20:03 +09:00
c0a0861897 Improve memory safety and alignment handling
Some checks failed
Publish NuGet Packages / publish (pull_request) Failing after 1m5s
- Updated `.gitignore` to include `.vscode/` and clarified comments.
- Introduced `SafeHandle` for managing memory alignment and safe access.
- Refactored `UnsafeArray<T>` to add bounds checking and alignment logic.
- Added `IUnsafeHashCollection<T>` for specialized hash-based collections.
- Refactored `UnsafeHashMap<TKey, TValue>` and `UnsafeHashSet<T>` to use `HashMapHelper<TKey>` with alignment support.
- Made `UnsafeSlotMap<T>` methods `readonly` for immutability.
- Enhanced `HashMapHelper<TKey>` with alignment-aware buffer management and validation.
- Updated benchmarks to use `UnsafeArray<Vector256<int>>` and added capacity checks.
- Incremented assembly version to `1.1.3` in `Misaki.HighPerformance.LowLevel.csproj`.
- Updated `Program.cs` to run `CollectionBenchmark` and demonstrate safe disposal handling.
2025-11-18 01:25:40 +09:00
24a7d49ae2 Upgrade to .NET 10 and refactor core components
Upgraded target framework to .NET 10 across all projects to leverage new features and improve performance.

Refactored `JobScheduler` to fix method naming inconsistencies and ensure proper resource disposal. Enhanced `AllocationManager` with safer memory operations and better performance handling. Simplified `ReadOnlyUnsafeCollection` enumerator logic for efficiency.

Overhauled `UnsafeBitSet` with new properties, improved bitwise operations, and optimized memory management. Updated `UnsafeSlotMap` and `ConcurrentSlotMap` for better validation and naming consistency.

Revised `MemoryLeakException` to use `ReadOnlySpan` for improved performance. Simplified `MathematicsBenchmark` logic and integrated `BenchmarkDotNet` for testing.

Added AOT compatibility settings for `Debug` and `Release` configurations. Introduced unit tests for `UnsafeBitSet` to validate functionality. Cleaned up unused code, improved readability, and ensured consistent naming conventions.

Updated project references and metadata for consistency. Enabled inline methods for `NET10_0_OR_GREATER` in `VectorGenerator`.
2025-11-14 11:14:09 +09:00
bc8b2c0aaa Fixed bug that SlotMap.Contains does not return a correct value.
Some checks failed
Publish NuGet Packages / publish (pull_request) Failing after 6s
2025-11-11 17:38:30 +09:00
fbe72e33f7 Refactor AllocationManager and enhance debug tracking
Refactored `AllocationManager` to introduce intrusive allocation tracking with `AllocationHeader` structs for debug mode. Added lightweight allocation counters for non-debug mode. Enhanced memory leak detection with detailed stack traces and `MemoryLeakException`.

Simplified `AllocationInfo` by removing the `Allocator` property. Updated `AllocationOption` enum to remove `UnTracked` and clarified documentation.

Improved unsafe collections (`UnsafeArray`, `UnsafeStack`, etc.) with strongly-typed enumerators and better compatibility with `IEnumerable<T>`. Enhanced `UnsafeStack` with a dedicated `Enumerator` struct and consistent constructor parameters.

Refactored `MemoryLeakException` to support detailed allocation info and improved stack trace formatting. Simplified `MemoryUtility` by removing redundant null checks.

Added unit tests for `AllocationManager`, `UnsafeArray`, and `UnsafeStack` to validate memory management and functionality. Updated `Program.cs` with new examples.

Cleaned up namespaces, removed redundant `using` directives, and improved XML documentation. Applied `MethodImplOptions.AggressiveInlining` to performance-critical methods.
2025-11-06 01:28:43 +09:00
b914716225 Fix package dependency problem
All checks were successful
Publish NuGet Packages / publish (push) Successful in 1m47s
2025-11-04 20:48:25 +09:00
49e1171781 Refactor and enhance math and utility libraries
Some checks failed
Publish NuGet Packages / publish (push) Failing after 3m12s
Refactored `sincos` usage across `quaternion` and `random` to use `out` parameters for improved performance. Enhanced `random` struct with updated random direction generation methods.

Added new benchmarks in `MathematicsBenchmark` for vector operations, including SIMD-based `f4` struct. Downgraded target framework to `net9.0` for compatibility.

Introduced `ReadOnlyUnsafeCollection` for low-level memory management. Added utility methods in `CollectionUtility` for span creation and optimized list operations.

Renamed `MemoryUtilities` to `MemoryUtility` and updated all references. Enhanced `ObjectPool` with `Rent` and `TryRent` methods. Enabled `AllowUnsafeBlocks` and AOT compatibility in project configuration.

Performed general code cleanup, including removal of unused methods, improved formatting, and alignment with modern coding practices.
2025-11-04 14:53:01 +09:00
081103372f Refactor memory management and improve allocation APIs
Updated `ReallocFunc` to support `oldSize`, `newSize`, and `AllocationOption`, enabling more granular control over memory reallocation. Simplified `AllocationInfo` by removing the `FreeHandler` property. Enhanced `Reallocate` and `Allocate` methods in `AllocationManager` to handle memory clearing and tracking more effectively.

Refactored `UnsafeSparseSet` to use `UnsafeArray<T>` directly, added a `generations` array, and replaced the `freeList` with `UnsafeStack<int>` for better performance and simplicity. Updated `Resize`, `Add`, and `Remove` methods to improve memory handling and code clarity.

Introduced `AllocationOption` support in `Resize` methods across `IUnsafeCollection` implementations for flexible resizing behavior. Added `GetUnsafePtr` extension methods in `UnsafeUtilities` for direct access to span data.

Added new tests for `UnsafeSparseSet` to validate resizing, clearing, enumeration, and memory compaction. These changes improve memory management, enhance performance, and ensure correctness.
2025-10-08 15:40:49 +09:00
a92ab93731 Refactor and enhance math utilities and code generation
Refactored `StbImage` classes to be publicly accessible. Updated namespaces and introduced `NumericTypeAttribute` for metadata. Enhanced `VectorGenerator` with new utility methods (`any`, `all`, `length`, etc.) and improved code generation. Consolidated vector operations in `math` utilities.

Refactored `Plane` and `svd` classes for better encapsulation and readability. Improved `DynamicArray` with `uint` indexer support and cleaner loops. Added SIMD-based benchmarking placeholders in `MathematicsBenchmark`.

Removed redundant code and unused files, including `IUnsafeSet.cs`. Updated project file to include `CodeGen` as an analyzer. Introduced `SupportedVectorMath` and `SupportedMatrixMath` enums for better operation definitions.

Improved code style, fixed minor bugs, and cleaned up unused code in `Program.cs`. Enhanced maintainability and readability across the codebase.
2025-10-04 12:38:53 +09:00
ac73e28f26 Refactor and enhance math, memory, and utilities
Refactored `sincos` usage in `quaternion` to use tuple-based
returns for improved readability. Introduced a `random` struct
with methods for generating random values of various types
and dimensions, including ranges and directions. Added a
`DynamicArray` class for dynamic resizing and manipulation
of collections. Enhanced `SlotMap` with new methods for
safe access and updates.

Updated `uint` vector types with `NumericConvertable`
attributes for better type interoperability. Removed the
`MathUtilities` class and refactored `adj` and `adjInverse`
methods for encapsulation. Improved memory management
with `StackAllocator` and `UnsafeArray` enhancements.

Added geometry utilities like `AABB`, `OBB`, `Plane`, and
`SphereBounds` for 3D operations. Updated project
configuration for versioning and NuGet packaging.
Performed general code cleanup, improved validation, and
aligned with modern C# practices.
2025-09-23 22:57:12 +09:00
94f10de90e Added WaitAll and WaitAny to JobScheduler;
Added generation support to UnsafeSparseSet;
2025-09-11 18:45:40 +09:00
02e173415e Added new giteaaction 2025-09-11 10:54:34 +09:00
3923682b5e Enhance JobScheduler and related classes
Added XML documentation comments to the `JobScheduler` class and its methods.
Added a new method `GetJobStatus` in the `JobScheduler` class for job status retrieval.
Added a new `CollectionHandle` struct for collection management.
Added a new test class `TestUnsafeSparseSet` with unit tests for `UnsafeSparseSet`.

Changed the `WorkerThread` class to improve job retrieval logic with a new `FindJob` method.
Changed the `DynamicArena` class by removing commented-out code to streamline memory management.

Removed commented-out code in the `WorkerThread` class for improved readability.
Removed the `ArenaAllocator` struct from `AllocationManager` to clean up unused code.
Removed the `ParallelWriter` struct from `UnsafeSparseSet`, indicating a shift in handling sparse sets.
2025-09-10 13:17:17 +09:00
07c99b8a5a Refactor job system and update project configuration
Added:
- Added `JobExecutor.cs` for job execution management.
- Added `JobInfo.cs` to hold job execution information.
- Added `TestJobSystem.cs` for unit tests of the job system.
- Added `TestJobs.cs` for additional job implementation tests.
- Added `WorkerThread.cs` to manage worker threads for jobs.

Changed:
- Changed `AssemblyInfo.cs.cs` to include a global using directive for `unsafe JobExecuteFunc`.
- Changed `IJob.cs` to include an overload of the `Execute` method with a `threadIndex` parameter.
- Changed `JobHandle.cs` to include an `IsValid` property and updated internal structure.
- Changed `JobScheduler.cs` to improve job scheduling and management.
- Changed `JobsUtility.cs` to enhance job management functions.
- Changed `MemoryBlock.cs` to reference the heap from which memory was allocated.
- Changed `ParallelNoiseBenchmark.cs` to include benchmarks for the job system.
- Changed `Program.cs` to execute benchmarks instead of previous test code.

Removed:
- Removed `.gitignore` entries for default ignored files.
- Removed `JobBase.cs` to shift from structs to classes for jobs.
- Removed `JobExtensions.cs` indicating a change in job scheduling.
- Removed `JobStruct.cs` indicating a change in job structure.
- Removed `encodings.xml`, `indexLayout.xml`, and `vcs.xml` files to simplify project configuration.
- Removed fields from `JobData.cs` to simplify the job data structure.
- Removed `TestJobSystem.csproj` entries related to old project structure.
2025-09-08 23:17:22 +09:00
a2a760594e Enhance mathematical capabilities and job system
Added new numeric types for unsigned integers, including uint2, uint3, and uint4, along with their matrix types.
Added a new `quaternion` struct with constructors and methods for creating and manipulating quaternions.
Added methods for projecting and reflecting vectors, enhancing geometric operations.
Added utility functions for generating orthonormal bases and changing vector signs.
Added comprehensive unit tests for new mathematical functions and quaternion operations.
Added a high-performance job scheduling system with job management features and worker thread management.
Added new structs for job execution, allowing efficient job scheduling and execution.
Added utility functions for job execution, including methods for obtaining unique job IDs.

Changed access modifiers and property definitions in several files for improved clarity and maintainability.
Changed property definitions and method implementations in `ImageInfo.cs`, `ImageResult.cs`, and `ImageResultFloat.cs` for better readability.
Changed memory management functions in `CRuntime.cs` and improved memory allocation tracking in `MemoryStats.cs`.
Changed the project file to include references to necessary projects and enable unsafe code blocks.

Removed the `WorkerThreadPool.cs` file, integrating worker thread management directly into the `JobScheduler`.
Removed the `float4` struct and its associated methods and properties, transitioning to a new code generation strategy.
Removed the `float4.tt` template and other related files, indicating a shift in code generation approach.
Removed the `Vectorize.cs` file, indicating a change in how vector operations are handled.

Updated the `.gitignore` file to include IDE-specific settings.
Updated various XML files to define project components and structure.
Updated the `AllocationManager.cs` to improve memory allocation management and introduce new strategies.
Updated the `UnsafeArray.cs`, `UnsafeHashMap.cs`, and `UnsafeList.cs` to enhance performance and safety in unsafe contexts.
Updated error handling and function pointer management in `MemoryLeakException.cs` and `FunctionPointer.cs`.
Updated the `AssemblyInfo.cs` file to include global using directives for better code organization.
2025-09-06 12:07:02 +09:00
eeff3313b5 Add image processing and memory management features
Added new namespace `Misaki.HighPerformance.Image` for image processing, including classes for animated GIF handling and memory management.
Added `AnimatedFrameResult` class for individual frames in animated images.
Added `AnimatedGifEnumerator` class for enumerating frames in animated GIFs.
Added `ColorComponents` enum for different color formats.
Added `ImageInfo` struct for image dimensions and color components.
Added `CRuntime` class for low-level memory management functions.
Added `MemoryStats` class to track memory allocation statistics.
Added utility functions for creating multi-dimensional arrays.
Added new structures for fixed-size UTF-8 encoded strings.
Added benchmarking classes to test new memory management features.

Changed `StbImage.cs` to include new namespaces and functionality for image data manipulation.
Changed project files to target .NET 9.0 and enable new features.
Changed `Arena.cs` and `DynamicArena.cs` to use `nuint` for size parameters.
Changed `BitSet.cs` to enhance bit manipulation methods.
Changed `Program.cs` to run `FunctionPtrBenchmark` for performance testing.

Removed memory tracking code from `AllocationManager.cs`, including the `_allocated` dictionary and related logic.
Removed `Free` method from `IAllocator.cs` interface.
Removed `UNSAFE_COLLECTION_CHECK` preprocessor directive from the codebase.

Refactored various files to improve organization, moving from `Unsafe` to `LowLevel` namespace.
Refactored `MemoryUtilities` class to include new memory operation methods.
Refactored `UnsafeUtilities.cs` to support new collection structures.
2025-07-12 19:48:42 +09:00
d306f183de Refactor memory management in AllocationManager
Changed the `AllocationManager` to use `ThreadLocal<DynamicArena>` for thread-specific memory allocation.
Changed the `Initialize` method to directly validate `initialSize` and initialize the thread-local arena.
Changed the `Allocate` and `Realloc` methods to utilize the thread-local arena for memory operations.
Changed the `Free` method to remove unnecessary locking due to thread-local management.
Added a new private method `EnsureInitialized` to verify the initialization of the thread-local arena.
Added a public static method `ResetAll` to reset all thread-local arenas.
Changed the `ResetCurrent` method to reset only the current thread's arena.
Updated the `Dispose` method to clean up all thread-local arenas and clear the allocated dictionary.
Uncommented the `UNSAFE_COLLECTION_CHECK` directive for enhanced debugging checks in `AllocationManager`.
Changed `CollectionBenchmark` to call `AllocationManager.ResetCurrent()` after populating the `UnsafeArray<int>`.
2025-04-11 16:41:28 +09:00
691a336111 Refactor unsafe collections and benchmarks
Changed the `CollectionBenchmark` class to use unsafe code for improved memory operations and added benchmarks for stack-allocated arrays.
Changed the `ParallelNoiseBenchmark` class to remove the internal `NoiseJob` struct, promoting better organization.
Changed the `AllocationManager` class to remove the lock mechanism for thread safety and simplified the `Reset` method.
Changed the `Arena` and `DynamicArena` structs to include `Initialize` methods for better initialization control.
Changed the `UnsafeArray<T>`, `UnsafeHashSet<T>`, and `UnsafeList<T>` structs to improve element access and management.
Updated the `UnsafeCollectionExtensions` class to enhance usability with new methods for copying and converting collections.
Updated the `MemoryLeakException` class to provide more detailed stack trace information for better debugging.
Removed the usage of `UnsafeHashMap` in `Program.cs` and directly ran the `CollectionBenchmark`.
Added a new `NoiseJob` struct in `NoiseJob.cs` for generating gradient noise using `UnsafeArray<float>`.
Fixed minor typos and improved method signatures throughout the codebase for clarity.
2025-04-11 15:53:11 +09:00
463735a481 Update memory management and collection structures
Added `AllocationHandler` struct for memory allocation management.
Added `UnsafeArrayPool` class for pooling `UnsafeArray<T>` instances.
Added new `External` option to `Allocator` enum.
Added default constructors for `UnsafeList`, `UnsafeQueue`, and `UnsafeStack` using `Persistent` allocator.
Changed namespace in `AllocationManager` to `Misaki.HighPerformance.Unsafe.Buffer`.
Changed `MemoryLeakException` to use `MemoryLeakExceptionInfo` for better debugging.
Changed constructor behavior in `UnsafeArray` to clarify memory management responsibilities.
Changed `MemoryUtilities` to include null checks in `Free` and `AlignedFree` methods.
Removed unused using directive in `CollectionBenchmark.cs`.
Removed initialization of `AllocationManager` in `Program.cs`.
2025-04-05 16:07:04 +09:00
9eea53d8f1 Remove unused methods and project file
Removed the `CeilPow2` method and its associated using directive from `MathUtilities.cs`.
Removed the entire content of the `Misaki.HighPerformance.Mathematics.csproj` file.

Added new classes and structures

Added a new `MemoryLeakException` class to handle memory leak reporting in `MemoryLeakException.cs`.
Added a new `AllocationInfo` struct to store allocation details in `AllocationManager.cs`.

Changed memory management logic

Changed memory allocation handling in `Program.cs` by introducing `unfreeArray` and `unfreeList`.
Changed the `_allocated` dictionary in `AllocationManager.cs` from `UnsafeHashMap` to `Dictionary` and updated allocation logic to store `AllocationInfo`.
Modified allocation and reallocation logic in `AllocationManager` to include stack trace information in debug mode.
Updated disposal logic in `AllocationManager` to throw a `MemoryLeakException` for unfreed allocations.
2025-04-03 22:55:48 +09:00
791be1bed2 Refactor memory management and allocation strategies
Changed the `AllocationManager` initialization to specify size in `Program.cs` and commented out the disposal of `unfreeArray`.
Changed `UnsafeArray` to use `AllocationManager.Realloc` for memory reallocation.
Changed constructors of `UnsafeHashMap` and `UnsafeHashSet` to include an `AllocationOption` parameter for improved memory management.
Added a `Remove` method to `UnsafeHashMap` for key-value pair removal.
Changed `AllocationManager` to use a hash map instead of a queue for managing allocations.
Added a `Realloc` method in `AllocationManager` for handling memory reallocation.
Changed the `Free` method in `AllocationManager` to iterate through the hash map for freeing allocated memory.
2025-04-03 17:46:55 +09:00
3c555a9489 Update memory allocation practices and clean up code
Changed the `ParallelNoiseBenchmark` class to use `AllocationOption.None` for `UnsafeArray<float>` instances.
Changed the `AllocationOption` enum to replace `UnInitialized` with `None` and clarified the `UnTracked` option.
Changed constructors for `UnsafeArray<T>`, `UnsafeList<T>`, `UnsafeQueue<T>`, and `UnsafeStack<T>` to use `AllocationOption.None`.
Changed the `HashMapHelper<TKey>` constructor to accept an `AllocationOption` parameter for improved flexibility.
Changed the `Allocate` method documentation in `Arena.cs` to clarify memory management.
Improved the `AllocationManager` class with a default arena size and updated allocation logic to handle new `AllocationOption` flags.
Removed the import statement for `BenchmarkDotNet.Running` in `Program.cs` and added new imports for `Misaki.HighPerformance.Unsafe.Collections` and `Misaki.HighPerformance.Unsafe.Services`.
Added a new `UnsafeArray<int>` in `Program.cs` and called `AllocationManager.Dispose()` to clean up resources.
2025-04-03 16:59:32 +09:00
Misaki
1e00f4eb25 Enhance memory management and data structures
Updated `CollectionBenchmark` for setup/cleanup methods,
streamlined benchmarking in `Program.cs`, and improved
documentation in `AllocationOption` and `Allocator` enums.
Made `Enumerator` structs public in several collections
and clarified constructor parameters. Introduced a new
`UnsafeStack` struct for stack operations. Enhanced
`AllocationManager` with better memory tracking and
management, ensuring proper allocation and disposal.
2025-04-03 15:47:43 +09:00
Misaki
da64e07c6f Refactor allocation types and improve memory management
This commit renames `AllocationType` to `AllocationOption` across multiple files, enhancing clarity in memory allocation practices. Key updates include:
- Modifications to the `UnsafeArray`, `ParallelNoiseBenchmark`, `Arena`, and `DynamicArena` classes to utilize the new `AllocationOption`.
- Refactoring of the `AllocationManager` and `HashMapHelper` classes to support the new allocation strategy.
- Removal of the `Misaki.HighPerformance.Mathematics` project reference, indicating a restructuring of dependencies.
- Introduction of a new `MathUtilities` class for calculating the smallest power of two, aiding memory allocation strategies.

These changes collectively improve code maintainability and clarity in memory management.
2025-04-03 12:06:25 +09:00
48f2dce778 Enhance memory management and performance benchmarks
Added a new configuration setting in `.editorconfig` to sort system directives last and increased the maximum line length to 400 characters.
Added a new static class `MathUtilities` in `MathUtilities.cs` with a method `CeilPow2` for computing powers of two.
Added a new benchmark class `CollectionBenchmark` in `CollectionBenchmark.cs` to measure performance of standard versus unsafe arrays.
Added a new benchmark class `HashCodeBenchmark` in `HashCodeBenchmark.cs` to evaluate hash code generation performance.
Added new utility methods in `UnsafeUtilities.cs` for memory allocation and deallocation, including `Malloc`, `AlignedAlloc`, `Realloc`, and `Free`.
Added a new `AllocationType` enum in `AllocationType.cs` to specify memory allocation types.

Changed the project file `Misaki.HighPerformance.Mathematics.csproj` to target .NET 9.0 and enable implicit usings and nullable reference types.
Changed the `ParallelNoiseBenchmark` class in `ParallelNoiseBenchmark.cs` to improve memory allocation strategies and performance.
Changed memory management in `Arena.cs` and `DynamicArena.cs` to use custom `Malloc` and `Free` functions.
Changed the `IUnsafeCollection` interface in `IUnsafeCollection.cs` to include new methods for resizing collections and obtaining unsafe pointers.
Changed the `UnsafeArray.cs` to improve management of unsafe arrays, including constructor and method updates.
Changed the `UnsafeHashMap` and `UnsafeHashSet` classes to enhance performance and memory management.
Changed the `UnsafeCollectionExtensions` class to provide additional methods for copying elements and converting collections.
Changed the `ObjectPool` class in `ObjectPool.cs` to simplify cleanup and remove auto-cleanup functionality.
Changed job scheduling and worker classes in `JobExtensions.cs` and `JobWorker.cs` to improve job scheduling in a thread pool.

Removed commented-out code in `Program.cs` related to previous testing methods.
Removed auto-cleanup functionality from the `ObjectPool` class.
2025-04-03 09:13:07 +09:00
060b4c9477 Add benchmark method and improve Unsafe collections
Added a new benchmark method `For` in `ParallelNoiseBenchmark` to test gradient noise generation.
Added demonstration code for `UnsafeArray` in `Program.cs` with a custom `Test` struct.

Changed property accessors in `IUnsafeCollection<T>` to use `ref` returns for better memory efficiency.
Changed property accessors and indexers in `UnsafeArray<T>`, `UnsafeList<T>`, and `UnsafeQueue<T>` to return `ref` types.
Changed `TryDequeue` in `UnsafeQueue<T>` to return a default value instead of null.
Changed `Clear` and `Dispose` methods in `UnsafeQueue<T>` to reset size and offset.

Removed commented-out `BenchmarkRunner` code in `Program.cs`.
2025-03-27 12:51:00 +09:00
7bcd699eb9 Enhance noise generation and memory management
Added new noise generation methods in `ParallelNoiseBenchmark`, including `Frac`, `Lerp`, and `GradientNoiseDirect`, and updated the `GradientNoise` method to utilize them. Changed constants to use `_LENGTH` for consistency.

Changed `Arena` and `DynamicArena` classes to use `uint` instead of `ulong` for size fields, improving memory usage. Updated memory allocation to use `NativeMemory` for better performance and safety.

Updated `UnsafeArray<T>` and `UnsafeList<T>` classes to replace `Marshal` methods with `NativeMemory`, enhancing performance and safety. Modified `Dispose` methods to use `NativeMemory.AlignedFree`.

Added `MemoryUtilities` class with new methods for memory management, including `MemClear`, `MemSet`, `MemCpy`, `SizeOf`, and `AlignOf`, utilizing `NativeMemory`.

Fixed minor cleanup in the `ObjectPool` class's `Dispose` method.
2025-03-25 09:49:49 +09:00
aa1e9e6b1d Initial upload; 2025-03-25 00:55:48 +09:00