Skip to content

change block given condition in methods with explicit block #405

wants to merge 1 commit into from

2 participants

lest commented Nov 10, 2011

Use if block instead of if block_given? when block is explicit

It's more simple and also here is a benchmark

lest commented Nov 18, 2011

@rkh Could you give some comments? I really think it's reasonable change and it does some performance burst.

Sinatra member
rkh commented Nov 19, 2011

To be honest, I think this pull request is a bit ridiculous. The only place where this brings "performance" is in the body helper (all other methods are only called at load time). The impact of defining a method on that proc is so expensive though, that the "boost" becomes irrelevant. On implementations that support inlining (any common implementation but MRI), block_given? is faster, as it will become a single inlined assertion rather than a slot lookup.

Running an app using body with a block does not show any difference in terms of req/sec with or without this pull request on ant Ruby implementation (tried 1.8.7, 1.9.2, 1.9.3, Rubininus 2.0 and JRuby 1.6.5).

Please provide relevant benchmarks (i.e. how this influences Sinatra performance, no micro benchmarks).

@lest lest closed this Nov 19, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.