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

[BUG] Performance issue with Yojson #1703

Closed
vouillon opened this issue Oct 4, 2024 · 6 comments · Fixed by #1713
Closed

[BUG] Performance issue with Yojson #1703

vouillon opened this issue Oct 4, 2024 · 6 comments · Fixed by #1713
Labels

Comments

@vouillon
Copy link
Member

vouillon commented Oct 4, 2024

Parsing a large string (~ 1MiB) with Yojson is really slow. We should investigate why.

@vouillon vouillon added the bug label Oct 4, 2024
@hhugo
Copy link
Member

hhugo commented Oct 9, 2024

How slow is really slow ? Are you sure the slowness comes from yojson ? Can you describe the issue a bit more ?

@vouillon
Copy link
Member Author

The function Yojson.Safe.from_string is slow on large strings.

The main issue is that Buffer.add_sub_bytes is assuming that Bytes.unsafe_to_string is cheap (https://github.com/ocaml/ocaml/blob/42adb2793657f4ef4f72eb9fc362c73e8eb2eb9f/stdlib/buffer.ml#L162-L163).

Additionally, this function has the side effect of changing the representation of the byte string, which is then converted back from a string to an array in caml_lex_engine.

var buffer = caml_uint8_array_of_bytes(lexbuf[lex_buffer]);

@hhugo
Copy link
Member

hhugo commented Oct 11, 2024

I see. I was able to reproduce.

@hhugo
Copy link
Member

hhugo commented Oct 11, 2024

@vouillon, see ocaml/ocaml#13543

@vouillon
Copy link
Member Author

Cool! Thanks!

@hhugo
Copy link
Member

hhugo commented Oct 13, 2024

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

Successfully merging a pull request may close this issue.

2 participants