Skip to content

Reduce unnecessary cloning of versions AND slow convergence to the optimal context #1217

@skrynski

Description

@skrynski

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions