forked from isagalaev/ijson
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom event name interning to yajl2_c
Since its inception, the yajl2_c backend's performance has relied on a few tricks, one of the main ones being the fact that it uses its own global (now part of the module state) event name PyUnicode instances, since there are only so many event names that are always the same. Because internally the backend always uses these objects, we can perform direct pointer comparison when checking for event name equality. This works well for internal event names, but it actually breaks when users provide their own string instances. This can occur when doing event interception, or when using the *_coro function family. In these cases, it cannot be guaranteed that input event names are the same objects are the global ones kept by yajl2_c, and therefore pointer comparison will fail, leading to confusing behaviour. This commit remedies this situation by performing our own poor man's interning logic. When calling into the send() methods of the yajl2_c objects, we try to find the internal event name object corresponding to the one given by the user based on its hash value (but checking for pointer equality first, we might still be receiving a yajl2_c global object)x, and use that internally. If no corresponding event name can be found then it is used as-is, which will lead to undefined behaviour (but that's the case already too, even with the other backends). Since the yajl2_c backend itself doesn't invoke the send() functions directly but the underlying send_impl() ones (to save an unnecessary tuple packing/unpacking), performance isn't affected for normal use cases. New tests have been added showing these scenarios where user-provided event name instances are fed into the different methods. These tests fail for yajl2_c if the changes in this commit are not applied. Signed-off-by: Rodrigo Tobar <[email protected]>
- Loading branch information
Showing
7 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters