-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
buffer: align chunks on 8-byte boundary #1126
Conversation
When slicing global pool - ensure that the underlying buffer's data ptr is 8-byte alignment to do not ruin expectations of 3rd party C++ addons. NOTE: 0.10 node.js always returned aligned pointers and io.js should do this too for compatibility.
024592c
to
c7111d5
Compare
Suggested reviewer: @trevnorris @bnoordhuis |
@@ -157,6 +157,12 @@ function palloc(that, length) { | |||
var buf = sliceOnto(allocPool, that, start, end); | |||
poolOffset = end; | |||
|
|||
// Ensure aligned slices | |||
if (poolOffset & 0x7) { | |||
poolOffset |= 0x7; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, why is this line needed if the condition already succeeded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poolOffset = 1
poolOffset & 0x7 === 1
poolOffset |= 0x7
=>0x7
poolOffset++
=>0x8
- Voila,
poolOffset
is aligned!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mscdex in other words, I'm just setting all bits that are lower than alignment value and increment the number to align it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A less convoluted way of writing that is poolOffset = (poolOffset & ~7) + 8
:-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used something like this: poolOffset += 8 - poolOffset % 8;
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I do this to for variable-size alignment or just non-power-of-two.
LGTM |
@bnoordhuis thanks! @trevnorris : please put your LGTM here too, just to make sure that I'm not messing up with any performance-critical things here. |
LGTM |
lgtm |
oh, last minute LGTM :) I almost pushed the commit without your name in |
When slicing global pool - ensure that the underlying buffer's data ptr is 8-byte alignment to do not ruin expectations of 3rd party C++ addons. NOTE: 0.10 node.js always returned aligned pointers and io.js should do this too for compatibility. PR-URL: #1126 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Bert Belder <bertbelder@gmail.com>
Landed in 07c0667, thank you! |
When slicing global pool - ensure that the underlying buffer's data ptr
is 8-byte alignment to do not ruin expectations of 3rd party C++ addons.
NOTE: 0.10 node.js always returned aligned pointers and io.js should do
this to for compatibility.