-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Performance compared to lua-cjson. #275
Comments
Wow. This is what I have been planning to do with RapidJSON. I have just peek into the code and find out it uses I will need some time to do profiling with your performance tests. P.S. Testing performance on Travis seems not a good practice. As the loading of the server node may be changing all the time. |
VC2013 32-bit /Ox
It seems writing string in RapidJSON performance is worse than lua-cjson (e.g. |
I reviewed the code for stringifying string. They are actually very similar. The difference is that, static void json_append_string(lua_State *l, strbuf_t *json, int lindex)
{
const char *escstr;
int i;
const char *str;
size_t len;
str = lua_tolstring(l, lindex, &len);
/* Worst case is len * 6 (all unicode escapes).
* This buffer is reused constantly for small strings
* If there are any excess pages, they won't be hit anyway.
* This gains ~5% speedup. */
strbuf_ensure_empty_length(json, len * 6 + 2);
strbuf_append_char_unsafe(json, '\"');
for (i = 0; i < len; i++) {
escstr = char2escape[(unsigned char)str[i]];
if (escstr)
strbuf_append_string(json, escstr);
else
strbuf_append_char_unsafe(json, str[i]);
}
strbuf_append_char_unsafe(json, '\"');
} After trying to do the same logic in RapidJSON (just hacking, not fully implemented for all streams, and drop transcoding functionality), it gains some improvements but still worse than cjson:
|
That nice improvement.
|
Today I learnt about Just changing one line of code in template<typename T>
RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
// Expand the stack if needed
if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count >= stackEnd_))
Expand<T>(count);
T* ret = reinterpret_cast<T*>(stackTop_);
stackTop_ += sizeof(T) * count;
return ret;
} The performance boosts for both parsing, and stringifying to StringBuffer, as they both uses
This technique shall be applied to string encoding/decoding also. |
Sounds like a good idea. 👍 |
I try to rerun the benchmark on OS X: After properly build in release configuration:
Enable
The most obvious improvement is |
#544 Optimized Before:
After
Among above, the affected tests are:
|
rerun the lua performance test, showing the same kind of improvements:
|
@miloyip |
I have write a json module for lua based on RapidJSON.
The performance test result over lua-cjson is:
On windows:
My json module performance a bit slower than cjson when processing booleans nulls strings. but much faster than cjson when processing numbers.
I guess is because the MSVC is slow when convert numbers <--> string.
On Linux (tested on Travis):
My json module only a bit faster when encoding numbers.
My question is:
The text was updated successfully, but these errors were encountered: