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

Too many serializations #1605

Closed
Finomnis opened this issue Jun 12, 2015 · 5 comments
Closed

Too many serializations #1605

Finomnis opened this issue Jun 12, 2015 · 5 comments
Milestone

Comments

@Finomnis
Copy link
Contributor

I believe that there is an unnecessary serialization of arguments for remote action invocations.

Here is a minimal example:

// Copyright (c)       2013 Martin Stumpf
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/hpx_start.hpp>
#include <hpx/include/iostreams.hpp>
#include <hpx/lcos/future.hpp>


class testclass{

    private:
        // serialization support
        friend class hpx::serialization::access;

        ///////////////////////////////////////////////////////////////////////
        template <typename Archive>
        void save(Archive& ar, const unsigned int version) const
        {
            hpx::cout << "serialize" << hpx::endl;
        }

        ///////////////////////////////////////////////////////////////////////
        template <typename Archive>
        void load(Archive& ar, const unsigned int version)
        {
            hpx::cout << "deserialize" << hpx::endl;
        }

        HPX_SERIALIZATION_SPLIT_MEMBER()


};



void testfunc(testclass t)
{

}

HPX_PLAIN_ACTION(testfunc, testfunc_action);


int hpx_main(int argc, char* argv[])
{
    {
        testclass t;

        auto localities = hpx::find_remote_localities();

        HPX_ASSERT(localities.size() > 0);

        hpx::naming::id_type locality = localities[0];

        hpx::async<testfunc_action>(locality, t).wait();
    }
    return hpx::finalize();
}

int main(int argc, char* argv[])
{
        // initialize HPX, run hpx_main.
        hpx::start(argc, argv);

        // wait for hpx::finalize being called.
        return hpx::stop();
}

The output of this program is:

serialize
serialize
deserialize

In my opinion, the serialization function should not get called twice.

@hkaiser hkaiser added this to the 0.9.11 milestone Jun 12, 2015
@hkaiser
Copy link
Member

hkaiser commented Jun 12, 2015

That's on purpose. The first serialization is using an archive which only keeps track of how many bytes would have been written in order to correctly estimate the overall required buffer size for the actual serialization.

@hkaiser hkaiser closed this as completed Jun 12, 2015
@Finomnis
Copy link
Contributor Author

Ok, I see.
U sure that this is efficient? For serialization of large buffers, that basically means two data-copies.

@Finomnis
Copy link
Contributor Author

If at all, i think it would be more efficient to have a buffer that grows exponentially, in multiple pieces, and then merge them via memcpy instead of doing an entire serialization twice.

@Finomnis
Copy link
Contributor Author

Ok, I guess the first serialization doesn't write any data.
This entire thing does make sense.

@sithhell
Copy link
Member

@Finomnis, there is no copying going on in the first pass, we just look and see how many bytes would have been copied to completely avoid reallocation.

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

No branches or pull requests

3 participants