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

Replace linked list with VecDeque #14

Merged
merged 4 commits into from
Sep 23, 2024
Merged

Replace linked list with VecDeque #14

merged 4 commits into from
Sep 23, 2024

Conversation

Igigog
Copy link

@Igigog Igigog commented Sep 21, 2024

Hey :)
I was looking around out of curiosity and found a nice place to reduce the amount of unsafety. This PR replaces Linked List-y structure of JobQueue with Rust's own VecDeque. As far as I can tell, there is no difference in performance (~1% difference on my machine). Also:

  1. It is easier to read.
  2. Tests for the queue are not needed anymore, since there is no reason to test VecDeque.
  3. Since there is no sentinel value, pop_back and pop_front are safe.

@dragostis
Copy link
Owner

Thank you for the PR! :)

I actually started writing this project with VecDeque, but I was actually pushing the whole Job onto the queue instead of the pointer which was slower. Nice to see that it actually works!

Copy link
Owner

@dragostis dragostis left a comment

Choose a reason for hiding this comment

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

Looks pretty good, but there are a few things that can be further simplified before we can merge this. I would also keep the pop_* methods unsafe.

@Igigog
Copy link
Author

Igigog commented Sep 21, 2024

Indeed, using fut as a queue marker made things quite a bit easier and ~2% faster on my machine, which makes this PR at least not slower than main branch. I have renamed is_in_queue method to is_waiting, since it doesn't really show if it's in queue anymore.

As for pop_* methods, pop_back is now very obviously safe; I maintain that pop_front is not unsafe, but I don't really care tbh, might as well mark it unsafe.

Copy link
Owner

@dragostis dragostis left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes! Ofc, the pop methods don't need to be unsafe.

@dragostis dragostis merged commit 2a10201 into dragostis:main Sep 23, 2024
5 checks passed
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.

2 participants