Hacker News new | past | comments | ask | show | jobs | submit login

Yes there is some concern that it would affect code size and/or make some optimizations impossible, but on the latter I have yet to see hard data that that is the case. We're talking about adding about 1-2 cycles of latency.

Note that the branch can be implemented in a way that compilers will lower into a CMOV, making the code size issue almost moot. I implemented that in fbstring back in the day:

https://github.com/facebook/folly/commit/be4c6d6b3e21914df8a...

This is the entirety of size():

    0f b6 57 17             movzbl 0x17(%rdi),%edx
    b8 17 00 00 00          mov    $0x17,%eax
    48 29 d0                sub    %rdx,%rax
    48 0f 48 47 08          cmovs  0x8(%rdi),%rax
A bit more than a MOV, but not that much.

> I'd personally think it would be interesting to test artificially increasing the sizeof() of strings from 24 bytes (the minimum needed to store a pointer, size and capacity) to something like 64 bytes, just to get longer strings using the SSO

And libstdc++ is actually 32 bytes :( It's easy to template on the inline capacity, you can look at llvm::SmallVector or folly::small_vector, but vocabulary types should have the smallest possible footprint. Vast majority of instances are either empty, or very small (think keys in a map).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: