Too slow
Closed this issue · 5 comments
When I serialize a Msgpack object(which is almost 49m bytes) to a file, it takes me as much as a whole minute
below is my code:
ofstream fout;
fout.open(afb_file);
MsgPack mg_pj;
MsgPack::object mg_root = { { "screenw", base_ui_component::screenw },
{ "screenh", base_ui_component::screenh },
{ "current_txt_index", g_cur_texture_id_index } };
MsgPack::array mg_res_list;
for (auto& res_unit : g_vres_texture_list)
{
MsgPack::binary txtdata;
txtdata.reserve(res_unit.texture_widthres_unit.texture_height * 4);
txtdata.resize(res_unit.texture_widthres_unit.texture_height * 4);
glBindTexture(GL_TEXTURE_2D, res_unit.texture_id);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &txtdata[0]);
MsgPack::array texture_coordinate_list;
for (auto& tcd_unit:res_unit.vtexture_coordinates)
{
texture_coordinate_list.push_back(MsgPack::object{ { "file_name", tcd_unit._file_name },
{ "x0", tcd_unit._x0 }, { "y0", tcd_unit._y0 }, { "x1", tcd_unit._x1 }, { "y1", tcd_unit._y1 } });
}
mg_res_list.push_back(MsgPack::object{ { "txtpk_file", txtdata }, { "txtpk_fmt", texture_coordinate_list } });
}
mg_root["txtres_list"] = mg_res_list;
mg_root["control_objects"] = get_ui_component(_pj);
mg_pj = mg_root;
string str_output;
mg_pj.dump(str_output);
fout << str_output << endl;
fout.close();
Hi @viter-oliver
I evaluated the following code but it takes about three seconds on my environment.
So I cannot reproduce this issue.
Do you think the following example ? Is it correct ?
#include <iostream>
#include <fstream>
#include <msgpack11.hpp>
using namespace msgpack11;
int main(int argc, char const *argv[]) {
std::ofstream fout;
fout.open("./dump.mp");
MsgPack mg_pj;
MsgPack::object mg_root = {
{ "screenw", 512 },
{ "screenh", 512 },
{ "current_txt_index", 15 }
};
MsgPack::array mg_res_list;
for(int i = 0; i < 64; i++)
{
MsgPack::binary txtdata;
txtdata.reserve(512 * 512 * 4);
txtdata.resize(512 * 512 * 4);
MsgPack::array texture_coordinate_list;
for(int j = 0; j < 64; j++ )
{
texture_coordinate_list.push_back(MsgPack::object{
{ "file_name", "aaaaaaaa" },
{ "x0", 256 },
{ "y0", 512 },
{ "x1", 1024 },
{ "y1", 2048 }
});
}
mg_res_list.push_back(MsgPack::object{
{ "txtpk_file", txtdata },
{ "txtpk_fmt", texture_coordinate_list }
});
}
mg_root["txtres_list"] = mg_res_list;
mg_root["control_objects"] = MsgPack::object{};
mg_pj = mg_root;
std::string str_output;
mg_pj.dump(str_output);
fout << str_output << std::endl;
fout.close();
return 0;
}
if your don't mind, can you share some codes which takes whole minutes ?
Hi Masahiro Wada
Thank you so much for your prompt response.
I have tested your example in my computer, but it takes almost 3 minutes(in the process of debugging, I have found most of the time is not consumed by outputting to file, but the function MsgPack::dump(string&)),
Isn't my msgpack11 the latest version?
the below is my test project.
msgpack11test.zip
@viter-oliver
Thanks for your quick reply !
I think this behavior is as expected.
In debugging build, msgpack11 is too slow.
Because it writes its content byte by byte.
Could you use this library as release build ?
@ar90n
Yes, you are right, release version takes about 3 seconds.
Release version basically meet my need, but I still hope msgpack11 could be faster, After all, message pack has made the claim about its performance, it is 4 times faster than Protobuf.
So, will msgpack11 be optimized faster in the future?