Skip to content

Conversation

@dolio
Copy link
Contributor

@dolio dolio commented Dec 15, 2025

This PR includes some improvements to the emitJson replacement in the runtime.

  • Switched to using a strict text builder instead of aggregating up IO Text. Exceptions are managed via a final evaluate instead.
  • Made the function produce a single chunk rope, which speeds up eventual conversion to bytes.
  • Improved the predicate looking for characters to escape, which took a considerable portion of the time in a lot of cases (anything with lots of objects has a lot of strings to check).

- Switched to using a strict text builder instead of aggregating up
  `IO Text`. Exceptions are managed via a final `evaluate` instead.
- Made the function produce a single chunk rope, which speeds up eventual
  conversion to bytes.
- Improved the predicate looking for characters to escape, which took a
  considerable amount of the time in a lot of cases.
@aryairani
Copy link
Contributor

does this need dogfooding or is it pretty solid? i'm thinking about doing another release soon

@dolio
Copy link
Contributor Author

dolio commented Dec 15, 2025

Maybe hold off until after just in case.

It seems like the one-chunk thing might make parsing slower (investigating). That's kind of a silly use case (emit then parse), but I suppose there could be other gotchas.

Edit: think I know why. The way the parser is written, it calls some text functions (like splitAt) that call length on chunks, but with one enormous chunk that's bad because Text is O(n) length.

dolio and others added 2 commits December 15, 2025 15:53
The one from the library calls `length` on chunks, which is very bad for
huge chunks, and seems like it might even be costly on more modest chunks.
@dolio
Copy link
Contributor Author

dolio commented Dec 15, 2025

Wrote a custom version of splitAt. Now the single-chunk parse seems to be faster than the version running on modest sized chunks.

@dolio
Copy link
Contributor Author

dolio commented Dec 15, 2025

Manually ran CI against the ormolu commit here:

https://github.com/unisonweb/unison/actions/runs/20247859959

I think it fixed the problem from the previous commit.

@aryairani aryairani merged commit d9a5ddb into trunk Dec 21, 2025
29 checks passed
@aryairani aryairani deleted the topic/emit-json branch December 21, 2025 03:30
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.

4 participants