Skip to content
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

stack overflow on large inputs #1

Open
eniac314 opened this issue Sep 22, 2018 · 1 comment
Open

stack overflow on large inputs #1

eniac314 opened this issue Sep 22, 2018 · 1 comment

Comments

@eniac314
Copy link

I am getting this error Uncaught RangeError: Maximum call stack size exceeded when trying to prettify large input strings on chrome (and some versions of firefox)

You can see the error here:
https://ellie-app.com/3qgxLtypPdZa1

Switching to the pretty function (commented in the ellie) from the package emilianobovetti/elm-yajson seems to work even for very large input.

@YetAnotherMinion
Copy link
Member

Thank you for taking the time to create a bug report.

The short answer is that this library is just a thin wrapper over a parser combinator library designed for generic document layout into a fixed width terminal. It is gratuitously recursive when generating its internal AST.

Because we only care about JSON, and we probably don't really care about tight width guarantees (JSON does not support folding whitespace inside literals), a more naive stringify implementation custom written for JSON is almost certainly a better fit.

My reasoning for the current implementation was to have small arrays or maps combined on one line. That was aesthetically please to me personally because long lists of numbers would not expand into many line monstrosity. Looking at what this library does today, it appears that behavior was lost sometime ago during the implementation and I did not notice.

In my view there are two bugs in this report:

  1. Perfectly reasonably sized JSON causes Maximum call stack error (I was expecting megabytes, not a few kilobytes).
  2. Arrays are not rendered compactly.

Action

I will find where the callstack gets deep. (Hopefully it is in the layout code and not the AST generation. I can always speed up recursive layout code by modifying it to be tail recursive). I can always temporarily bugfix with a naive formatter that replicates the existing output, and continue to work on my preferred formatting.

I will update you by end of day tomorrow what I have found and what my plan is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants