mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
Add optional C extension wrapper for Python JSON parsing
The pure Python in-tree JSON parser is *much* slower than the in-tree C JSON parser. A local test parsing a 100Mb JSON file showed the Python version taking 270 seconds. With the C wrapper, it took under 4 seconds. The C extension will be used automatically if it can be built. If the extension fails to build, a warning is displayed and the build is restarted without the extension. The Serializer class is replaced with Python's built-in JSON library since the ability to process chunked data is not needed in that case. The extension should work with both Python 2.7 and Python 3.3+. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -18,6 +18,11 @@ import sys
|
||||
import six
|
||||
from six.moves import range
|
||||
|
||||
try:
|
||||
import ovs._json
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
__pychecker__ = 'no-stringiter'
|
||||
|
||||
escapes = {ord('"'): u"\\\"",
|
||||
@@ -165,6 +170,12 @@ class Parser(object):
|
||||
# Maximum height of parsing stack. #
|
||||
MAX_HEIGHT = 1000
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
try:
|
||||
return ovs._json.Parser(*args, **kwargs)
|
||||
except NameError:
|
||||
return super(Parser, cls).__new__(cls)
|
||||
|
||||
def __init__(self, check_trailer=False):
|
||||
self.check_trailer = check_trailer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user