Commit 7ef02f1
committed
Improve decode() performance by counting using pointers, not indexes.
This makes a huge impact on MSVC/x64, which apparently had a
hard time optimizing the alphabet_indexes[current_index] access
syntax (which is really &alphabet_indexes[0] + current_index)
to something more efficient.
Other compilers get a minor improvement in benchmark numbers.
As follows (MinSizeRel build, benchmarked on my laptop):
Decoding to string (buffers of size 32768):
VS2017/Win32: previously 128, now 97 (default C++ standard)
VS2017/x64: previously 340, now 88 (default C++ standard)
Clang 6/x64: previously 74, now 80 (C++17)
GCC 7.3/x64: previously 79, now 78
Decoding to vector<uint8_t>:
VS2017/Win32: previously 99, now 94
VS2017/x64: previously 328, now 86
Clang 6/x64: previously 72, now 78
GCC 7.3/x64: previously 78, now 76
Clang is doing slightly worse after this patch, but not nearly
enough to veto this patch, given the massive VS2017 improvement.
As a bonus, here are current Release build numbers:
VS2017/Win32: enc 101, dec string 106 (gaspardpetit benchmark)
VS2017/x64: enc 99, dec string 102 (gaspardpetit benchmark)
Clang 6/x64: enc 93, dec string 73, dec vector<uint8_t> 73 (C++17)
GCC 7.3/x64: enc 32, dec string 62, dec vector<uint8_t> 62 (C++17)
GCC Release comes out as a definitive winner here, beating the
Apache base64 implemention and the polfosol snippet by a few
microseconds in both the encoding benchmark, and Apache again
by a few microseconds in decoding as well, as measured by
gaspardpetit/base64 when built in the same Release build.
It's still about half as slow as the polfosol decoding snippet,
but then again, polfosol does not do any handling of special
cases whereas cppcodec handles zero termination characters,
throws on invalid (out of alphabet) characters and on
incorrect padding.
I had an earlier patch to reduce the number of checks but it
actually made things worse (probably due to increased code size)
so we'll leave it at this for now.1 parent 0b716ed commit 7ef02f1
1 file changed
+29
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
332 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
333 | 336 | | |
334 | 337 | | |
335 | 338 | | |
336 | 339 | | |
337 | 340 | | |
338 | 341 | | |
339 | | - | |
340 | | - | |
| 342 | + | |
| 343 | + | |
341 | 344 | | |
342 | 345 | | |
343 | 346 | | |
344 | | - | |
| 347 | + | |
345 | 348 | | |
346 | | - | |
| 349 | + | |
347 | 350 | | |
348 | | - | |
| 351 | + | |
349 | 352 | | |
350 | 353 | | |
351 | 354 | | |
352 | | - | |
| 355 | + | |
353 | 356 | | |
354 | 357 | | |
355 | 358 | | |
356 | 359 | | |
357 | | - | |
358 | | - | |
359 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
360 | 363 | | |
361 | 364 | | |
362 | 365 | | |
363 | 366 | | |
364 | 367 | | |
365 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
366 | 371 | | |
367 | | - | |
| 372 | + | |
368 | 373 | | |
369 | | - | |
| 374 | + | |
| 375 | + | |
370 | 376 | | |
371 | 377 | | |
372 | | - | |
| 378 | + | |
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
376 | | - | |
377 | | - | |
| 382 | + | |
| 383 | + | |
378 | 384 | | |
379 | 385 | | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
383 | | - | |
| 389 | + | |
384 | 390 | | |
385 | | - | |
386 | | - | |
| 391 | + | |
| 392 | + | |
387 | 393 | | |
388 | 394 | | |
389 | 395 | | |
390 | 396 | | |
391 | | - | |
| 397 | + | |
392 | 398 | | |
393 | 399 | | |
394 | 400 | | |
395 | | - | |
| 401 | + | |
| 402 | + | |
396 | 403 | | |
397 | 404 | | |
398 | 405 | | |
| |||
0 commit comments