Coder Social home page Coder Social logo

Comments (8)

dmbates avatar dmbates commented on June 2, 2024

You're right. I'll make the corresponding changes.

from rcall.jl.

dmbates avatar dmbates commented on June 2, 2024

This is getting more complicated than I first imagined. Right now I define the SEXP type in Julia as immutable and consisting only of a Ptr{Void}. But you can't put a finalizer on such an object, because it corresponds to a bitstype. One way out is to declare SEXP as a type, not an immutable type. There will be some cost in performance but probably not a measurable difference.

from rcall.jl.

randy3k avatar randy3k commented on June 2, 2024

I am thinking there should be two versions of asSEXP. One does the preserving and releasing whereas the other variant does not. The reason I suggest this is because releasing an R object could take a lot of time when the number of preserved objects is large. (it is based on some pairlist in R, and checking is done recursively).

For example, if one runs x = RCall.asSEXP([1:10]) 10 thousands times. If the preserving procedure is included, than there will be ten thousands of which x in the memory. Of course, 9999 of them will be collected when GC, but you can imagine that this step could be time consuming.

I don't really know the best way to resolve this issue. Perhaps we need more experts to give advices.

from rcall.jl.

dmbates avatar dmbates commented on June 2, 2024

Perhaps create an abstract type AbstractSEXP with a concrete immutable type SEXP and a concrete type protectedSEXP?

For the time being I suggest keeping the current scheme (everything is the mutable type SEXP and is protected) until we see if there are performance problems. I doubt very much that R_ReleaseObject is going to be the bottleneck but we can check. I looked and R_ReleaseObject does do a linear search on a cons list.

from rcall.jl.

randy3k avatar randy3k commented on June 2, 2024

Actually, the bottleneck can be easily seen by

julia> @time for i in 1:100000 RCall.asSEXP([1:10]) end
elapsed time: 0.44483907 seconds (26656472 bytes allocated, 68.26% gc time)

julia> @time for i in 1:100000 RCall.asSEXP([1:10]) end
elapsed time: 144.245652407 seconds (28945552 bytes allocated, 99.90% gc time)

The second run is extremely slow since GC is freeing the memory allocated by the first run.

from rcall.jl.

dmbates avatar dmbates commented on June 2, 2024

Right now I am working on documentation. If you want to create a PR, please do.

from rcall.jl.

randy3k avatar randy3k commented on June 2, 2024

Perhaps we can add an additional argument own in asSEXP.

When own is true, the R object is persevered, otherwise, it is unprotected.

How does it sound? I could do this easy PR if you agree.

from rcall.jl.

randy3k avatar randy3k commented on June 2, 2024

I think it could be closed as the PR #59 is coming.

from rcall.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.