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

Manually implement JSON array printing to avoid stack overflow #16583

Merged
merged 1 commit into from
Feb 8, 2025

Conversation

mrmr1993
Copy link
Member

@mrmr1993 mrmr1993 commented Feb 7, 2025

Yojson's pretty printing creates a huge call stack using the built-in OCaml list iterators. Since we're only printing an array of objects, we can easily implement a tail-recursive version.

This fixes #16579.

Yojson's pretty printing creates a huge call stack using the built-in
OCaml list iterators. Since we're only printing an array of objects, we
can easily implement a tail-recursive version
@mrmr1993 mrmr1993 requested a review from a team as a code owner February 7, 2025 22:45
@mrmr1993
Copy link
Member Author

mrmr1993 commented Feb 7, 2025

!ci-build-me

Format.fprintf Format.std_formatter "[\n " ;
let print_comma = ref false in
List.iter accounts ~f:(fun a ->
if !print_comma then Format.fprintf Format.std_formatter "\n, "
Copy link
Member

@deepthiskumar deepthiskumar Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the comma before \n? That's how it is in the previous version, not sure if that makes any difference

@mrmr1993 mrmr1993 merged commit c7957ad into compatible Feb 8, 2025
46 checks passed
@mrmr1993 mrmr1993 deleted the feature/support-large-json-ledger-printing branch February 8, 2025 14:40
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

Successfully merging this pull request may close these issues.

2 participants