Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examine temporary tuple constructions during the runtime #15

Open
lemire opened this issue May 26, 2024 · 1 comment
Open

examine temporary tuple constructions during the runtime #15

lemire opened this issue May 26, 2024 · 1 comment

Comments

@lemire
Copy link
Member

lemire commented May 26, 2024

The struct_to_tuple function builds, at runtime, what is effectively a copy of any struct, but organized as a tuple.

So if you have...

struct mytype {
 std::string value1;
 std::string value2;
 int x;
}

Then it will construct (at runtime), something like this...

std::tuple<std::string,std::string,int> t;

That's at runtime, so it is not at all free.

You can help things a little bit by casting to references so that you have...

std::tuple<std::string&,std::string&,int&> t;

In at least one benchmark, just replacing the copies by reference made a large difference (see #14).

Still, we construct an std::tuple for every single struct or class we serialize. While this construction is convenient, it might be unnecessary. A sufficiently advanced compiler can probably lift the overhead, but it might be better if we could get rid of this intermediate construction.

@lemire
Copy link
Member Author

lemire commented May 28, 2024

Turns out that it is quite easy to remove the temporary tuples, see commit cd436d2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant