Skip to content

Added NumString, usize based string#21

Open
Wicpar wants to merge 1 commit into
paulocsanz:mainfrom
Wicpar:num_string
Open

Added NumString, usize based string#21
Wicpar wants to merge 1 commit into
paulocsanz:mainfrom
Wicpar:num_string

Conversation

@Wicpar

@Wicpar Wicpar commented Dec 25, 2022

Copy link
Copy Markdown
Contributor
  • Added usize based string
  • Added it to benchmarks
  • it's a LOT faster than SmallString.
  • still missing most functions and a bit of docs, but nothing to large, just copy paste the array_string ones.

…enchmark. At least 50% performance over array_string
@paulocsanz

Copy link
Copy Markdown
Owner

Pretty cool trick, seems promising! Does that also work with u128, and possibly with multiple fields? So we can get a bigger string than 8 ASCII characters? Is usize instead of u64 intentional btw?

There seems to be a lot of future in this!

@Wicpar

Wicpar commented Dec 26, 2022

Copy link
Copy Markdown
Contributor Author

Usize guarantees maximum speed as it will always be a register.
U64 seems natural but in the end numtraits are not the way to go.
Maybe i'll try a generalized case since consts are not stable enough to be used effectively.
We could do u128 without issues but i expect it to be a lot slower.
In essence all that is needed is a bit field since all that is done is shifting things around while preserving endianness for instant str transmute.

@Wicpar

Wicpar commented Dec 26, 2022

Copy link
Copy Markdown
Contributor Author

In my benchmark it took 1 cycle to copy, 4 cycles to from_str, 5 cycles to push_str.
It will be pretty hard to beat that, at least on an arm cpu.
For u128 each operation on x86 using sse is 2 cycles on most cpus, but there could be sse magic to shave a few instructions so it could be almost as fast as the usize one.

It would also be worth it to test on terget arch=native, and maybe even with avx 2 256 bit registers. (512 is just too rare to test)

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