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

Strange stream object copying while parsing #30

Closed
miloyip opened this issue Jun 29, 2014 · 1 comment · Fixed by #32
Closed

Strange stream object copying while parsing #30

miloyip opened this issue Jun 29, 2014 · 1 comment · Fixed by #32

Comments

@miloyip
Copy link
Collaborator

miloyip commented Jun 29, 2014

https://code.google.com/p/rapidjson/issues/detail?id=78

In a rapidjson reader class there's some strange code:

template<typename Stream>
void SkipWhitespace(Stream& stream)
{
    Stream s = stream;  // Use a local copy for optimization
    while (s.Peek() == ' ' || s.Peek() == '\n' || s.Peek() == '\r' || s.Peek() == '\t')
        s.Take();
    stream = s;
}

Why stream object is reassigned two times, what optimization this gives comparing to direct accessing it via reference? What if stream object copying is a heavy process by itself and also can cause an exception? What if I want to create stream class with non-copyable semantic? For me all of this is a clear pessimization instead of optimization.

@miloyip
Copy link
Collaborator Author

miloyip commented Jun 29, 2014

I have re-tested the impact after removal of these "optimizations". Results.
There is around 10%-20% overheads if disabling this "overhead".
I will try to add a switch which is specified by stream class.

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

Successfully merging a pull request may close this issue.

1 participant