Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JobHandle pure struct for stackalloc compatibility #34

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

LilithSilver
Copy link
Collaborator

Resolves #31 by adding a caching system to associate Job and Scheduler classes to a JobHandle that just stores integer IDs.

Ran a few benchmarks; no significant performance impact; it only has to do a couple extra dictionary/array lookups per Schedule and Complete call.

@LilithSilver LilithSilver requested a review from genaray February 16, 2024 05:55
Comment on lines +11 to +21
/// <summary>
/// Assigns schedulers an ID, and a cache of tracked jobs.
/// This way, we can store a Scheduler and a Job on a JobHandle by integer ID,
/// so that stackalloc JobHandle[] can work. Otherwise the managed types would prevent it.
/// </summary>
// A dictionary is OK because we only add when we initialize a new scheduler.
// It otherwise doesn't use memory.
// Accesses could be sliiiightly faster if we used an array and recycled IDs but not appreciably so,
// particularly for the overhead it would involve.
private static readonly Dictionary<int, (JobScheduler Scheduler, Job[] JobIds)>
_schedulerCache = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep thats right. Im fine here with a dictionary. Just wondering how fast or slow it would be to use an array instead ^^ But that's not a high priority here.

@genaray genaray merged commit ded2656 into genaray:master Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot stackalloc JobHandle[]
2 participants