-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R-package] manage Dataset and Booster handles as R external pointers (fixes #3016) #4265
Conversation
/gha run r-solaris Workflow Solaris CRAN check has been triggered! 🚀 solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-e77325aba0e449bebe84249015a5240b |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
/gha run r-solaris Workflow Solaris CRAN check has been triggered! 🚀 solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-d68ab45fd2514e2982267336296db17b |
Wonderful!
as it was suspected in #3016 (comment)
Any ideas why it doesn't and whether we should create a separate issue for these warnings as this PR is closing #3016? |
Please create a separate issue for it and I can investigate it (and document which specific combinations of operating system + R version + compiler + installation method it occurs for) in the future. |
@StrikerRUS I'm back at a computer now so I can make this issue. |
created #4273 to track the compiler warning |
Thank you very much! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice PR!
Please consider checking some my questions and cleanup suggestions below.
Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: failure ❌. |
/gha run r-solaris Workflow Solaris CRAN check has been triggered! 🚀 solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-847f0335b7b8431fab8a6bd16e415eb6 |
Hmmm, valgrind test is failing due to the time limit.
Rerunning... |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
😬 I hope it was something temporary, but I could understand if it wasn't. As of this PR, R is taking on more responsibility for allocating and freeing memory, and we know that the version of R instrumented with |
whew, seems that it succeeded. Total duration of https://github.com/microsoft/LightGBM/actions/runs/833251558 was 1 hour, 50 minutes, 46 seconds. I think that if we see timeout issues again in the future, we should increase the allowed time by another 30 minutes. |
Agree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woo-hoo! Thank you!
Excited about this one!! |
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Fixes #3016.
Contributes to #4208, might help with #4034.
Description
When the R package calls functions from the C++ side that create persistent objects in memory, like a Dataset or Booster, it stores a pointer to the memory address of such objects in a "handle". Today, these handles are stored in a double on 64-bit systems and as an int32 on 32-bit systems.
LightGBM/R-package/R/utils.R
Lines 9 to 15 in f831808
Today, the R package uses LightGBM's custom R-to-C interface to manage these handles. This can lead to issues like #4208, and generally exposes LightGBM to compatibility problems if new versions of R introduce changes that require corresponding changes in that custom interface.
This PR proposes replacing that custom management of "handles" with R's built-in pattern for such things. R's C API has a concept called "external pointers" designed for exactly this purpose.
From https://cran.r-project.org/doc/manuals/r-release/R-exts.html#External-pointers-and-weak-references
Notes for Reviewers
This only fixes #3016 if is is merged after #4256.
The "References" section below contains links to the resources that helped me to understand these concepts better, and they might help reviewers to understand these changes.
References