Re: [Rd] [External] JIT compiler does not compile closures with custom environments

2021-08-18 Thread Taras Zakharko
Thanks for the explanation, Luke! I’ll keep this behavior in mind. > On 18 Aug 2021, at 16:45, luke-tier...@uiowa.edu wrote: > > On Wed, 18 Aug 2021, Duncan Murdoch wrote: > >> On 18/08/2021 9:00 a.m., Taras Zakharko wrote: >>> I have encountered a behavior of R’s JIT compiler that I can’t qui

Re: [Rd] [External] Re: JIT compiler does not compile closures with custom environments

2021-08-18 Thread Duncan Murdoch
On 18/08/2021 10:45 a.m., luke-tier...@uiowa.edu wrote: On Wed, 18 Aug 2021, Duncan Murdoch wrote: On 18/08/2021 9:00 a.m., Taras Zakharko wrote: I have encountered a behavior of R’s JIT compiler that I can’t quite figure out. Consider the following code: f_global <- function(x) {

Re: [Rd] [External] Re: JIT compiler does not compile closures with custom environments

2021-08-18 Thread luke-tierney
On Wed, 18 Aug 2021, Duncan Murdoch wrote: On 18/08/2021 9:00 a.m., Taras Zakharko wrote: I have encountered a behavior of R’s JIT compiler that I can’t quite figure out. Consider the following code: f_global <- function(x) { for(i in 1:1) x <- x + 1 x } f_env <-

Re: [Rd] JIT compiler does not compile closures with custom environments

2021-08-18 Thread Taras Zakharko
That’s the interim solution I am using right now (manually precompiling most functions), but I generate quite a lot of closures dynamically in my code and the potential performance loss is a bit worrying… I don’t think the current behavior is expected based on what the documentation says. Cheer

Re: [Rd] JIT compiler does not compile closures with custom environments

2021-08-18 Thread Duncan Murdoch
Forgot to add: you could define f_env like this to get it compiled: f_env <- local({ cmpfun(function(x) { for(i in 1:1) x <- x + 1 x }) }) Not as convenient as JIT, but it gets the job done... Duncan Murdoch On 18/08/2021 10:33 a.m., Duncan Murdoch wrote: On 18/08/2021 9:00 a

Re: [Rd] JIT compiler does not compile closures with custom environments

2021-08-18 Thread Duncan Murdoch
On 18/08/2021 9:00 a.m., Taras Zakharko wrote: I have encountered a behavior of R’s JIT compiler that I can’t quite figure out. Consider the following code: f_global <- function(x) { for(i in 1:1) x <- x + 1 x } f_env <- local({ function(x) { for(i in 1

[Rd] JIT compiler does not compile closures with custom environments

2021-08-18 Thread Taras Zakharko
I have encountered a behavior of R’s JIT compiler that I can’t quite figure out. Consider the following code: f_global <- function(x) { for(i in 1:1) x <- x + 1 x } f_env <- local({ function(x) { for(i in 1:1) x <- x + 1 x } }) compiler::ena