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

Use unsigned long long for object ID #10551

Merged
merged 1 commit into from Apr 17, 2024

Conversation

peterzhu2118
Copy link
Member

@peterzhu2118 peterzhu2118 commented Apr 16, 2024

Since unsigned long long are minumum 64 bits, we have at least 10**17 object IDs available, so there is no chance it will overflow.

Since unsigned long long are minumum 64 bits, we have at least 10**17
object IDs available, so there is no chance it will overflow.
@peterzhu2118 peterzhu2118 changed the title Use long long for object ID Use unsigned long long for object ID Apr 16, 2024
@nobu
Copy link
Member

nobu commented Apr 16, 2024

It is very unlikely, but not "no chance".

id = objspace->next_object_id;
objspace->next_object_id = rb_int_plus(id, INT2FIX(OBJ_ID_INCREMENT));
id = ULL2NUM(objspace->next_object_id);
objspace->next_object_id += OBJ_ID_INCREMENT;
Copy link
Member

Choose a reason for hiding this comment

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

Needs overflow check?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's necessary. If we allocated 1000 object IDs every millisecond (i.e. 1,000,000 per second), it would take 15,000 years for it to overflow.

(((2**64) / 40) / ((1000 * 60 * 60 * 24) * 1000)) / 365

@peterzhu2118 peterzhu2118 merged commit ee6e591 into ruby:master Apr 17, 2024
100 checks passed
@peterzhu2118 peterzhu2118 deleted the long-long-obj-id branch April 17, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants