Skip to content

Performance wise, which is better: .get with a block or without a block when parsing JSON? #169

Answered by ioquatix
postmodern asked this question in Q&A
Discussion options

You must be logged in to vote

It's generally safer to use the block form if you can since the response will be closed correctly in (almost) every case (except fatal, unrecoverable errors). There should be no difference in performance. However, the code in the first example is unsafe, as you don't have an ensure block to close the connection. If the JSON fails to parse, you may leak the response which is bad.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@postmodern
Comment options

@ioquatix
Comment options

Answer selected by postmodern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants