Live data from Hacker News

Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

lemire.me

31–40 of 51 posts

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#31
post #25
post #20

Earlier quoted context omitted.

humans putting text into form fields will never go away probably, so you will always have to do this at some point.

This doesn't appear to implement trimming the front and back, just the entire string.

Yes, a much rarer thing.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#32
post #5

The complexity almost looks like an April Fools joke.

But if it's hidden behind a standard library's 'trim' functions it's all fine to me; I don't need to know how it works under the hood, but want to rely on the maintainer's knowledge that their implementation is as fast and efficient as possible on whichever architecture. Low level string operations happen so often under the hood in any application that 10x more code and complexity in an implementation is worth it if…

It doesn’t need to be “As fast as possible” it just needs to be faster than the I/O. For sure, congrats that it is X times faster but the writer doesn’t really describe performance in terms of real world constraints.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#33

Earlier quoted context omitted.

But if it's hidden behind a standard library's 'trim' functions it's all fine to me; I don't need to know how it works under the hood, but want to rely on the maintainer's knowledge that their implementation is as fast and efficient as possible on whichever architecture. Low level string operations happen so often under the hood in any application that 10x more code and complexity in an implementation is worth it if…

It doesn’t need to be “As fast as possible” it just needs to be faster than the I/O. For sure, congrats that it is X times faster but the writer doesn’t really describe performance in terms of real world constraints.

I/O is fast, and efficiency matters for every workload. The sooner your CPU is done running code, the sooner it can go into an energy saving state. Energy saving means a longer battery life on portable computers, and less cost in the server case. Remember that people are running algorithms like this "in the cloud" against millions of concurrent requests. The 40Gbps network card can keep the CPU busy, and users are waiting for you to be done. Writing efficient code to make 1 computer do the work of 2 is just operational cost savings 101.

When I was at Google there was a "rules of thumb" page that described how much of your time X performance was worth. I always looked at that before micro-optimizing, but also always came out ahead. I remember a coworker and I redesigning one of our subsystems late on some Friday evening; the rules of thumb said that the performance improvement we predicted, at our scale, was worth a month of SWE time. We did it in 2 hours. So we came out ahead, and our system worked better. (I joked that my colleague and I would be taking 2 extra weeks of vacation.)

TL;DR performance matters everywhere. The one user using an interactive tool on their workstation will appreciate their day not being wasted by random pauses. The person out and about on their phone will appreciate the additional battery life. And your company's bean counters will be quite happy to hear that your cloud bill or data center expense forecast for next year is down. Finally, it's fun! Truly a win/win. Make it fast!

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#34

Earlier quoted context omitted.

But if it's hidden behind a standard library's 'trim' functions it's all fine to me; I don't need to know how it works under the hood, but want to rely on the maintainer's knowledge that their implementation is as fast and efficient as possible on whichever architecture. Low level string operations happen so often under the hood in any application that 10x more code and complexity in an implementation is worth it if…

It doesn’t need to be “As fast as possible” it just needs to be faster than the I/O. For sure, congrats that it is X times faster but the writer doesn’t really describe performance in terms of real world constraints.

Not really. If you're 4x faster than IO, the CPU can do something else while waiting for IO (e.g. run another thread).

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#35

In order for this to matter, you'd need to expect the possibility of strings with huge numbers of leading spaces. Why then would you use this naive algorithm for comparison? An obvious and more straight forward improvement would be to compare 4 bytes at a time with 0x20202020. (or maybe 8) There would be a maximum of 3 spaces to identify individually.

I was confused too but the author uses “trim” to mean “remove anywhere in the string”, rather than just from the beginning and end.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#36
post #35

In order for this to matter, you'd need to expect the possibility of strings with huge numbers of leading spaces. Why then would you use this naive algorithm for comparison? An obvious and more straight forward improvement would be to compare 4 bytes at a time with 0x20202020. (or maybe 8) There would be a maximum of 3 spaces to identify individually.

I was confused too but the author uses “trim” to mean “remove anywhere in the string”, rather than just from the beginning and end.

What are the use cases for that, though?

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#37
post #36
post #35

Earlier quoted context omitted.

I was confused too but the author uses “trim” to mean “remove anywhere in the string”, rather than just from the beginning and end.

What are the use cases for that, though?

Maybe for processing the code for an obfuscated C contest?

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#38

Earlier quoted context omitted.

It doesn’t need to be “As fast as possible” it just needs to be faster than the I/O. For sure, congrats that it is X times faster but the writer doesn’t really describe performance in terms of real world constraints.

I/O is fast, and efficiency matters for every workload. The sooner your CPU is done running code, the sooner it can go into an energy saving state. Energy saving means a longer battery life on portable computers, and less cost in the server case. Remember that people are running algorithms like this "in the cloud" against millions of concurrent requests. The 40Gbps network card can keep the CPU busy, and users are wa…

What was the rule of thumb?

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#39
post #36
post #35

Earlier quoted context omitted.

I was confused too but the author uses “trim” to mean “remove anywhere in the string”, rather than just from the beginning and end.

What are the use cases for that, though?

There's a ton if you think of it as a byte array, rather than just a string. For example, network proxies that may remove various protocol TLV options from a packet.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#40

SVE and SVE2 are similar to Intel's AVX512-etc for vector, I would use intrinsics instead of hand crafting ASM code, unless it's a performance bottleneck. And yes if you want to play with SVE, Amazon's own ARM chip is the best one available now, maybe the only one in fact, for the general public.

Just to be clear, SVE is similar to AVX512 but the “Scalable” part is that the length is not hard-coded to any set number of bits or elements. It is more like the vector computers of old, such as the Cray-1. This means there is no need for continually updating the instruction set with longer and longer versions of the same instructions. Hopefully this leads to a more stable base and wider adoption, we’ll see how that…

I'm not really convinced we need to continually update the instruction set with non-scalable vector instructions either tbh, it seems like we've stalled on 256 bit wide instructions to the point where AMD is emulating 512 bit instructions using 256 bit wide execution units and the performance benefits of 512 bit wide instructions even on Intel is marginal at best.

That's not to say scalable instructions are a bad idea. It certainly makes it easier to make small CPUs which support all the software written for vector instructions without having to emulate 256 or 512 bit wide execution units.

Post reply on HN