isagalaev / ijson

Iterative JSON parser with Pythonic interface
http://pypi.python.org/pypi/ijson/
Other
615 stars 134 forks source link

Claim finite state machine, but really is not #38

Closed socketpair closed 9 years ago

socketpair commented 9 years ago
print [i for i in ijson.items(StringIO('['* 500), '')]

will generate long trace-back like:

...

.../ijson/backends/python.pyc in parse_array(lexer)
    136         if symbol != ']':
    137             while True:
--> 138                 for event in parse_value(lexer, symbol, pos):
    139                     yield event
    140                 pos, symbol = next(lexer)

.../ijson/backends/python.pyc in parse_value(lexer, symbol, pos)
    114             yield ('boolean', False)
    115         elif symbol == '[':
--> 116             for event in parse_array(lexer):
    117                 yield event
    118         elif symbol == '{':

.../ijson/backends/python.pyc in parse_array(lexer)
    136         if symbol != ']':
    137             while True:
--> 138                 for event in parse_value(lexer, symbol, pos):
    139                     yield event
    140                 pos, symbol = next(lexer)

.../ijson/backends/python.pyc in parse_value(lexer, symbol, pos)
    114             yield ('boolean', False)
    115         elif symbol == '[':
--> 116             for event in parse_array(lexer):
    117                 yield event
    118         elif symbol == '{':

...

But instead, it should make highly-enclosed arrays for that case, consuming memory (heap), but not the stack!

isagalaev commented 9 years ago

Uhm… Where does it claim to be a state machine? In fact, it doesn't claim pretty much anything. It's just an implementation with its own idiosyncrasies and limitations, it doesn't owe anything to the world, sorry :-)