You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
@matthewmcgarvey Would it actually make sense to wait till crystal-lang/crystal#10716 gets merged in? I hope it would make into Crystal 1.1.0, which shouldn't be too far ahead.
I believe using .to_json(response) is a current recommended way for performant code I nCrystal and maybe it's better to keep benchmark code as it is and just update to Crystal version where this is fixed once it's released?
@vlazar if the difference in performance really is due to the multiple calling of flush, then this change will still be faster since calling io.print(...) does not flush the io.
I've looked into most of the major frameworks and they all do it this way as well.
Mainly, this has made me wonder why HTTP::Server::Response is an IO at all.
OTOH .to_json creates new objects while .to_json(response) does not? I guess the performance impact could be different depending on the size of the serialized object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
response.print(...)is WAY faster than.to_json(response)for some reason. Local test on /json went from 80k per second to 220k per second.