Skip to content

Slow processing of JSON #1425

@kellyjonbrazil

Description

@kellyjonbrazil

Can I do anything to optimize the performance of highlighting JSON in my app, or is this working as designed?

class JelloStyle(Style):
    styles = {
        Name.Tag: 'bold ansiblue',     # key names
        Keyword: 'ansibrightblack',    # true, false, null
        Number: 'ansimagenta',         # int, float
        String: 'ansigreen'            # string
    }

print(highlight(output, JsonLexer(), Terminal256Formatter(style=JelloStyle))[0:-1])

(I remove the last character because it seems for some reason highlight adds a newline character, but that doesn't seem to affect performance)

When I use the highlight function on a relatively large (6MB) JSON file, it adds 13 seconds to the output time:

time cat ls-R.out | jc --ls | jello -m
real    0m3.101s
user    0m1.727s
sys 0m0.537s

vs.

time cat ls-R.out | jc --ls | jello
real    0m16.916s
user    0m14.624s
sys 0m0.721s

Using the plain TerminalFormatter didn't seem to improve performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions