Open Bug 1844513 Opened 2 years ago Updated 2 years ago

Move from out parameter to std::optional for pickling interface

Categories

(Core :: IPC, task)

task

Tracking

()

ASSIGNED

People

(Reporter: sergesanspaille, Assigned: sergesanspaille)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

The pickle interface is of the form bool ReadX(State*, out_type* result). This forms a natural barrier for the compiler when it fails to inline it.

In the context of -ftrivial-auto-var-init, the following pattern:

int result;
if(ReadInt(state, &result)) {...}

is problematic because it's not possible for the compiler to ensure result is always initialized before use, unless it can inline all the ReadInt body, which it doesn't.

An alternative is to change the signature of ReadX to std::optional<out_type> ReadX(State*). From the caller perspective, it always yield an initialized object, so that's compatible with -ftrivial-auto-var-init, but it's also the prefered, modern approach. In many a case, the code generation is either equivalent to the previous interface, or better.

See https://godbolt.org/z/fdq4bb1zf and https://godbolt.org/z/e5TzcoTTh for examples of both interfaces.

std::optional has several benefit compared to using an out parameter: it
leads to better code generation as there are less pointer around for the
compiler to track.

This also prevents insertion by -ftrivial-auto-var-init of extra memory store
that show up in the profile hot map.

As a side effect, get rid of a memcpy optimization that is no longer
relevant in 2023.

Assignee: nobody → sguelton
Status: NEW → ASSIGNED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: