[#98621] Re: Function getlogin_r()'s protoype] — Bertram Scharpf <lists@...>
FYI,
3 messages
2020/06/02
[#98947] [Ruby master Feature#16986] Anonymous Struct literal — ko1@...
Issue #16986 has been reported by ko1 (Koichi Sasada).
66 messages
2020/06/26
[#98962] [Ruby master Bug#16988] Kernel.load loads file from current directory without '.' in path — misharinn@...
Issue #16988 has been reported by TheSmartnik (Nikita Misharin).
5 messages
2020/06/26
[#98969] [Ruby master Feature#16994] Sets: shorthand for frozen sets of symbols / strings — marcandre-ruby-core@...
Issue #16994 has been reported by marcandre (Marc-Andre Lafortune).
7 messages
2020/06/26
[#100117] [Ruby master Feature#16994] Sets: shorthand for frozen sets of symbols / strings
— matz@...
2020/09/25
Issue #16994 has been updated by matz (Yukihiro Matsumoto).
[ruby-core:98821] [Ruby master Feature#12901] Anonymous functions without scope lookup overhead
From:
ko1@...
Date:
2020-06-16 08:11:57 UTC
List:
ruby-core #98821
Issue #12901 has been updated by ko1 (Koichi Sasada).
I read this ticket and several comments:
## `Proc#call` calling performance
The performance gap is because of optimization level. We didn't optimize `Proc#call` enough, so the capturing is not a reason.
## capturing outer-scope (making closure)
We will introduce `Proc#isolate` which creates a Proc but accessing outer scope is not allowed for the parallel execution (Guild/Ractor). So we can make such Proc. However, the normal Proc is created before calling `Proc#isolate` (`Proc.new{...}.isolate`), So Proc capturing overhead is not avoided. `Proc.new(isolate: true){ ... }` can avoid it. New syntax
BTW `self` is same as outer-scope. Guild/Ractor replaces it using `instance_eval` technique.
----------------------------------------
Feature #12901: Anonymous functions without scope lookup overhead
https://bugs.ruby-lang.org/issues/12901#change-86184
* Author: schneems (Richard Schneeman)
* Status: Open
* Priority: Normal
----------------------------------------
Right now if you are writing performance sensitive code you can get a performance bump by not using anonymous functions (procs, lambdas, blocks) due to the scope lookup overhead.
https://twitter.com/apotonick/status/791167782532493312?lang=en
I would like to be able to create an anonymous function and specify I don't need it to perform the lookup when called.
I am thinking that this code:
~~~
Proc.new(scope: false) {|var| puts var }
~~~
Would be the equivalent of
~~~
def anon(var)
puts var
end
~~~
If you call it while trying to access something from outside of the scope it would error
~~~
var = "hello"
Proc.new(scope: false) { puts var }.call
# => NameError: undefined local variable or method `var' for main:Object
~~~
An example of a case where this could be used is found in https://github.com/rails/sprockets/pull/417. In this case we are getting rid of anonymous functions in favor of a method created with refinements. This solution works but it was not an obvious optimization. It would be convenient to have a syntax for defining anonymous functions that do not need access to caller scope.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>