4 ms·
One thing that is unsatisfactory here is that when you follow such a fast operation by another operation, you lose on memory access time if the string doesn't f
by amelius 6y ago
One thing that is unsatisfactory here is that when you follow such a fast operation by another operation, you lose on memory access time if the string doesn't fit in the cache. So if you want to compute g(f(s)), then you will always have to optimize g and f together.
- vardump 6y agoGood point. In that case you might for example need to splice about 8-16 kB substrings to UTF-8 validate, to strike a reasonable balance between loop setup costs etc. and not spilling L1 cache. You'd of course need to check every splice ends at a valid UTF-8 boundary. Streaming operation composition while not sacrificing memory bandwidth or excessive overhead for CPU's liking is pretty cumbersome. You definitely don't want to spill cache, but you also need avoid overhead by ensuring vectorized code can take full advantage of the CPU performance. Anyone who tries to achieve high performance in this kind of operations without a profiler is doomed.
- VHRanger 6y agoThis is a validation step, though. I'd understand if it was a parser, but you want to validate UTF-8 to avoid reading into garbage (or evil code injection). So at least for this case it's mostly going to be validate(x) -> parse(x)
- pjscott 6y agoThe approach here can be used to process strings in chunks without too much added complexity, and it has low setup/teardown costs. The lookup tables fit in three 128-bit SIMD registers so there's minimal cache pollution, which is my usual worry with clever table-driven schemes for accelerating things.