Skip to content

Optimize endian conversion functions - #3201

Merged
zuiderkwast merged 2 commits into
valkey-io:unstablefrom
zuiderkwast:bswap
Feb 15, 2026
Merged

zuiderkwast merged 2 commits into
valkey-io:unstablefrom
zuiderkwast:bswap

Conversation

@zuiderkwast

Copy link
Copy Markdown
Contributor

Replace the implementation of byte-reverse functions.

The new implementation compiles to a single bswap instruction. The old implementation didn't.

The new implementation is small and all in the .h file. The .c file is deleted.

On little-endian systems, this affects streams, module timers and cluster code and a few more things, where htonu64() is used for storing stream-id or timestamps in a rax in big-endian order.

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
@zuiderkwast
zuiderkwast merged commit fde31b0 into valkey-io:unstable Feb 15, 2026
21 of 22 checks passed
@zuiderkwast
zuiderkwast deleted the bswap branch February 15, 2026 22:54
harrylin98 pushed a commit to harrylin98/valkey_forked that referenced this pull request Feb 19, 2026
Replace the implementation of byte-reverse functions.

The new implementation compiles to a single bswap instruction. The old
implementation didn't.

The new implementation is small and all in the .h file. The .c file is
deleted.

On little-endian systems, this affects streams, module timers and
cluster code and a few more things, where `htonu64()` is used for
storing stream-id or timestamps in a rax in big-endian order.

---------

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
hpatro pushed a commit to hpatro/valkey that referenced this pull request Mar 5, 2026
Replace the implementation of byte-reverse functions.

The new implementation compiles to a single bswap instruction. The old
implementation didn't.

The new implementation is small and all in the .h file. The .c file is
deleted.

On little-endian systems, this affects streams, module timers and
cluster code and a few more things, where `htonu64()` is used for
storing stream-id or timestamps in a rax in big-endian order.

---------

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
nesty92 pushed a commit to nesty92/valkey that referenced this pull request Mar 12, 2026
- Revert getClientType() from static inline in server.h back to regular
  function in networking.c, removing the cache locality optimization
- Revert stream iterator to use start_key/end_key as encoded 128-bit
  big-endian values instead of streamID, using memcmp instead of
  streamCompareID for range checks
- Remove streamID2string() and simplify createStreamIDString() to use
  sdscatfmt directly
- Replace memcpy with individual byte assignments in ull2string()
- Move slot_migration_job back to client state structs group in server.h

https://claude.ai/code/session_01X12N98RpdCHX2dwW6RcXPs
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