Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rails uses unpack1 'm0' to decode base64 cookies. Recent work had improved the performance of unpack1 but I was somewhat disturbed that MRI did so much better once the decode string got larger. This PR fast paths m0 and will also use a version which does not use ByteBuffer.
This benchmark looks at some larger strings (note: largest one is a bit bigger than the max size of a cookie but it is close enough to 4096 to get an idea of the cost at that size:
So strangely we do not really fully catch on these larger base64 strings but the new version is quite a bit faster. I really wonder if there is a way to tweak this new version of unpack that can eliminate bounds checking. Nonetheless, these larger sizes are not what I am seeing in a simple Rails app. In that case I took the 4 decodes which happen and benched those:
(note: indy makes these numbers a little bit better but the vast bulk of performance is all in Java)
We can see here that we are winning in 3 out of 4 unpacks and we are now close on the 4th.
My long term view is that ByteBuffer is impairing our unpack performance and when we rewrite unpack impls we should move to all byte[] versions. This fast path probably will not be needed once that is done.
I would like to understand why we are not catching perf with MRI here for longer strings but this is a positive step forward.
A really wildly unrealistic but not difficult idea would be to split the decode string and process pieces across multiple threads.