-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Substantial performance penalty caused by polymorphic input adapter #1457
Comments
Yes, such a PR would be greatly appreciated!!! |
I've just spent a bit of time working on this, and I've hit a pretty big snag: Making the In c++17, with template deduction guides, it would be much more straightforward. But for c++11, I think the best I could do is create a few specific overloads for common use-cases like |
This might be unrelated LALR parsers has been been suggested in contribution guideline but it is probably outdated (e.g. the parser is not recursive anymore). Can re-implementing the parser in some other form help to improve the performance? What is the reason to believe they can the improve the performance compared to current hard-crafted parser? Are they theoretically more efficient than current parser or it is a matter of chance/code generation that we end up with a faster parser? |
Yes, the comment is outdated. The parser now is not recursive any more. I used parser generators like bison in the past and I did not like the fact that this library parsed JSON in such a "manual" way. I guess now parsing performance could be rather improved by avoiding copies or allocations. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Has any more attention been put into this? I was running some profiles recently, and the polymorphic calls to the input/output adapters was showing up on the profile higher than I would like. |
No unfortunately not. I will reopoen and hope for a PR. |
My PR (for the input part of the problem) is still almost ready to go. The remaining problem is still supporting The issue is that Edit: I've managed to work around the issue without reverting to the polymorphic interface by adding a new overload to the main API functions, relying on the fact that the |
For reference, in my opinion, a nicer fix would have been to deprecate the bracket enclosed syntax, and add the two-parameter overload to parse() in order to match the |
Can we add the overload function even if not deprecating the old one? As a faster path for those who care? |
My old comment about having a fast path vs a slow path does not apply to my current PR. All code paths are "fast" while maintaining the current API, it's just that the user-facing interface is a little clumsy if you look at it from too close. |
Yeah, I'm not a fan of that pattern. Okay, thanks. Would be nice to get this into the library. :) |
We've been testing this on our very busy implementation (JSON parsing time is about 20% of the total profile), and found it to do exactly as advertised; noticeable boost in performance, no code changes required. Would indeed be nice to see this PR accepted. |
One report; we're in the process of moving from clang 7.0.1 to 9.0.1 here. Apropos to this change, while 7.0.1 compiled clean, we see the following warning with 9.0.1:
And that's valid; the const data member prevents the type from being movable. |
Good catch. It's unfortunate that no test caught this, despite coverage staying at 100%... |
The latest update resolves the warning for me on the 9.0.1 compiler |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I ran a quick-and-dirty-ish devirtualization test by
Before:
After:
Which represents a 3-10% speedup across the board.
Once correctly implemented, this should not cause any API change whatsoever.
Is this something worth pursuing? If there's interest, I'll draft a clean PR for it.
The text was updated successfully, but these errors were encountered: