Commit 0818c05
rpc: optimize tuple deserialization when the types are default-constructible
rpc deserialization cannot assume the types that make up the return
tuple are default-constructuble, and cannot deserialize directly into
the tuple constructor, so it is forced to construct a default-constructible
tuple formed by wrapping every T with std::optional, deserializing into
that, and then converting the temporary tuple into the return tuple
by calling std::optional::value() for each element. This wrapping and
unwrapping is wasteful, and while the compiler could theoretically
fix everything up, in practice it does not.
We notice that the first value can in fact be deserialized in the
tuple constructor arguments, since there's no ordering problem for it.
So we remove the std::optional wrapper for it unconditionally.
For the rest of the elements, we wrap them with std::optional only
if they are not default constructible. If they are, we leave them unchanged.
Finally, the unwrapping process calls std::optional::value if the type
was wrapped; and if none of the types were wrapped (which ought to be the
common case), we return the temporary tuple without any unwrapping,
reducing data movement considerably.
The optimization is written in a way to also include the previous
optimization when the tuple size was <= 1.
Testing on ScyllaDB's messaging_service.o, we see another reduction
in .text size:
text data bss dec hex filename
6758116 48 236 6758400 672000 messaging_service.o.before
6741352 48 236 6741636 66de84 messaging_service.o.after
About 17kB.
Closes #25231 parent fba36a3 commit 0818c05
1 file changed
+72
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
348 | 389 | | |
349 | 390 | | |
350 | 391 | | |
351 | 392 | | |
352 | 393 | | |
353 | 394 | | |
354 | 395 | | |
355 | | - | |
| 396 | + | |
356 | 397 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
367 | 428 | | |
368 | 429 | | |
369 | 430 | | |
| |||
0 commit comments