Skip to content
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

Making R internals more ALTREP friendly #23

Open
DavisVaughan opened this issue Jul 4, 2024 · 5 comments
Open

Making R internals more ALTREP friendly #23

DavisVaughan opened this issue Jul 4, 2024 · 5 comments
Labels
C Issues requiring knowledge of C PLUS 2024 Issues reserved for R Dev Day @ PLUS 2024

Comments

@DavisVaughan
Copy link

I've been working on an ALTREP "view" class, and have discovered a number of small places where I think base R itself could be a little more ALTREP friendly. I'd be interested in working on a few of these next week if there is support for it, I think it could be a really tractable win for r-dev-day with small and well scoped issues to tackle!


In particular, there are a few places I've found so far where R uses, say, LOGICAL() where it could instead use LOGICAL_RO(). These are cases where it seems like R only needs a read only pointer into the data. This would be more friendly to ALTREP classes that can provide a readonly pointer easily, but would have to materialize to provide a writable pointer (like an ALTREP "view").

All 3 of these currently force a materialization of my ALTREP class due to requesting a writable pointer, when I think they only need a readonly one.


In addition to these, I think that ExtractSubset() (used by the R level [, and many other places) could be modified to have really nice efficiency gains for ALTREP types. It currently calls the corresponding *_ELT() method on each index. I was thinking that alternatively it could try to see if a call to Dataptr_or_null() returns a cheap read only dataptr that it could use to extract from instead. I think that would make subset extraction way more efficient for ALTREP classes that can provide a readonly pointer easily (again, like a view).

I do realize there is an ALTREP Extract_subset method that I could implement for this last case, but subsetting is tricky to get exactly right for all cases, and I'd much rather just hand R a read only dataptr and let it handle the finer details of the subsetting!

Link: https://github.com/wch/r-source/blob/b9c83de5f7c9bb0b6dbe96b6d61a04d195b0cf2e/src/main/subset.c#L137

@DavisVaughan DavisVaughan added the C Issues requiring knowledge of C label Jul 4, 2024
@gmbecker
Copy link

gmbecker commented Jul 5, 2024 via email

@ltierney
Copy link

ltierney commented Jul 6, 2024

Seems worth a shot.

@gmbecker
Copy link

gmbecker commented Jul 7, 2024 via email

@hturner hturner added the PLUS 2024 Issues reserved for R Dev Day @ PLUS 2024 label Jul 11, 2024
@DavisVaughan
Copy link
Author

rlang side of this, which will be used as a test to make sure it is working r-lib/rlang#1725

@DavisVaughan
Copy link
Author

DavisVaughan commented Jul 12, 2024

Work with @Lime91, @krlmlr, and @gmbecker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Issues requiring knowledge of C PLUS 2024 Issues reserved for R Dev Day @ PLUS 2024
Projects
None yet
Development

No branches or pull requests

4 participants