-
Notifications
You must be signed in to change notification settings - Fork 19
Description
When running the snippet of code below using PIR_WARMUP=3 PIR_DEBUG=PrintPirAfterOpt,PrintToStdout
, we see that f1 (f[0])
shows up several times in the compilation log, each time with a more specific context. The reason is that it takes several passes to the compiler to reach the optimal context. When the eager_call pass picks up a better context, it clones the current version and changes it. This is also not ideal since oftentimes we could reuse the same version and change it in place (if we can show that is not referenced somewhere else).
Both problems should be looked into. The PR linked here attempts to limit the cloning of versions by keeping a simple refCount mechanism. It doesn't seem to show much benefits, so maybe it is not worth merging. However, it does fix the issue in the example and manages to reduce the number of times the function gets cloned.
f <- function() {
f1 <- function(x) {
#print("inner")
x + 4L
}
for (i in 1:10) {
print(f1(i))
}
rir.functionInvocations(f1)
}
f()
f()
f()
f()
f()
f()
f()