Skip to content

ARROW-13164: [R] altrep vectors from Array with nulls - #10730

Closed
romainfrancois wants to merge 32 commits into
apache:masterfrom
romainfrancois:ARROW-13164_altrep_with_nulls
Closed

ARROW-13164: [R] altrep vectors from Array with nulls#10730
romainfrancois wants to merge 32 commits into
apache:masterfrom
romainfrancois:ARROW-13164_altrep_with_nulls

Conversation

@romainfrancois

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

@romainfrancois

Copy link
Copy Markdown
ContributorAuthor

follow up after #10593

Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/array_to_vector.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
@romainfrancois
romainfrancoisforce-pushed the ARROW-13164_altrep_with_nulls branch from 0c68a38 to 498614dCompareJuly 16, 2021 14:49
@romainfrancois

This comment has been minimized.

@romainfrancois
romainfrancois marked this pull request as ready for review July 19, 2021 11:16
Comment threadr/tests/testthat/test-altrep.R Outdated
Comment threadr/src/array_to_vector.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/tests/testthat/test-altrep.R Outdated
Comment threadr/tests/testthat/test-altrep.R Outdated
Comment threadr/src/array_to_vector.cpp Outdated
Comment threadr/src/array_to_vector.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
@romainfrancois
romainfrancoisforce-pushed the ARROW-13164_altrep_with_nulls branch from b961c89 to 54b743cCompareAugust 17, 2021 09:54
@romainfrancois

Copy link
Copy Markdown
ContributorAuthor

Thanks for the reviews. I'll apply the relevant changes.

We now have AltrepArrayNoNulls<INTSXP|REALSXP> and AltrepArrayWithNulls<INTSXP|REALSXP> which are not all that different. I believe they can be merged into one template, which would perhaps slightly more involved Dataptr() ... methods...

@romainfrancois

Copy link
Copy Markdown
ContributorAuthor

I finally settled for a single altrep (template) class for both cases (the array has no nulls or the array has nulls).

The altrep object uses:

  • data1: an external pointer to the Array (well to a shared pointer to the Array)
  • data2: NULL until materialization is needed, then data2 is a standard (and immutable) R vector with the same data

Materialization is needed when:

  • we need the DATAPTR and the Array has nulls
  • we need a duplicate

Get_region() does not need to materialize the full vector.
Creating the altrep object does not alter the data to impose the R sentinel.

@pitroupitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to say that the AltrepArrayPrimitive seems very difficult to read and understand to me.

I would recommend:

  1. write extensive comments and explanations (including hyperlinks to R-related docs where necessary)
  2. choose naming wisely
  3. make sure no unused functionality or code paths are left
  4. make internal helper methods private, to better stress what is the "public" API
  5. also, make sure we're not doing any logic errors (if the user requests a writable array, do we really want to return a pointer to the immutable Arrow data?)

Comment threadr/src/array_to_vector.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
Comment threadr/src/altrep.cpp Outdated
@romainfrancois

Copy link
Copy Markdown
ContributorAuthor

Changed Dataptr(writeable = TRUE) so that the data is materialized.

@romainfrancois

Copy link
Copy Markdown
ContributorAuthor

🤔 I think now that means that if the data has been materialized, a Dataptr(writeable = TRUE) might have happened, and maybe the data has been written into. To be on the safe side, perhaps we should now treat the Array as obsolete and only ever use data2

@nealrichardson

Copy link
Copy Markdown
Member

maybe the data has been written into

We can write tests for this behavior, yeah?

@romainfrancois
romainfrancoisforce-pushed the ARROW-13164_altrep_with_nulls branch from 422c2fb to ef20698CompareAugust 30, 2021 15:52
@romainfrancois

Copy link
Copy Markdown
ContributorAuthor

The AltrepArrayPrimitive class now marks the altrep object as immutable. This makes this "a bad idea" to call Dataptr(writeable = TRUE) on it, and it should rather be accessed read-only.

However, if we make this an error, this fails in many many places, including identical() so we can't do that.

@romainfrancois
romainfrancoisforce-pushed the ARROW-13164_altrep_with_nulls branch from 2145dc4 to 83dcad9CompareAugust 31, 2021 08:40
@nealrichardson

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g r

@github-actions

Copy link
Copy Markdown

Revision: 763781c

Submitted crossbow builds: ursacomputing/crossbow @ actions-806

TaskStatus
conda-linux-gcc-py36-cpu-r40Azure
conda-linux-gcc-py37-cpu-r41Azure
conda-osx-clang-py36-r40Azure
conda-osx-clang-py37-r41Azure
conda-win-vs2017-py36-r40Azure
conda-win-vs2017-py37-r41Azure
homebrew-r-autobrewGithub Actions
test-r-depsource-autoAzure
test-r-depsource-systemGithub Actions
test-r-devdocsGithub Actions
test-r-gcc-11Github Actions
test-r-install-localGithub Actions
test-r-linux-as-cranGithub Actions
test-r-linux-rchkGithub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-base-latestAzure
test-r-rstudio-r-base-3.6-bionicAzure
test-r-rstudio-r-base-3.6-centos7-devtoolset-8Azure
test-r-rstudio-r-base-3.6-centos8Azure
test-r-rstudio-r-base-3.6-opensuse15Azure
test-r-rstudio-r-base-3.6-opensuse42Azure
test-r-ubuntu-21.04Github Actions
test-r-version-compatibilityGithub Actions
test-r-versionsGithub Actions
test-ubuntu-18.04-r-sanitizerAzure

@nealrichardson

Copy link
Copy Markdown
Member

I think that's all clean. @jonkeane do you want to do any benchmarking before we merge this?

@nealrichardson

Copy link
Copy Markdown
Member

@ursabot please benchmark lang=R

@ursabot

ursabot commented Aug 31, 2021

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = f60bc12 and contender = 763781c. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Provided benchmark filters do not have any benchmark groups to be executed on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Finished ⬇️2.19% ⬆️1.46%] ursa-i9-9960x
[Skipped ⚠️ Only ['C++', 'Java'] langs are supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Supported benchmarks:
ursa-i9-9960x: langs = Python, R, JavaScript
ursa-thinkcentre-m75q: langs = C++, Java
ec2-t3-xlarge-us-east-2: cloud = True

@jonkeane

Copy link
Copy Markdown
Member

Yeah, we should run these manually. I'll try to get to that tomorrow. None of the array conversion benchmarks have been wired up in the benchmarks package, so we don't have them available on conbench right now.

@jonkeane

Copy link
Copy Markdown
Member

OK, I just ran Array to R benchmarks locally, and the results are very impressive. I've added in other types (even though they are not (yet) backed by altrep). I've also tested both chunked and non-chunked arrays, and with nulls and without.

TL;DR:

For floats + ints we see huge speed ups (~10x faster) in both arrays with and without nulls as well as in arrays and chunked arrays (at least in the case where there is a single chunk*).

I'm still investigating what's going on with the two fannie parquet file reads that show up as regressions. If anything, this should have sped them up.

  • – we don't yet have fixtures with chunked arrays with multiple chunks. But I simulated this with a csv (which does come in with multiple chunks) and multi-chunk arrays aren't (yet) supported:
library(arrow)
nyctaxi<- read_csv_arrow("~/repos/ab_store/data/nyctaxi_2010-01.csv.gz", as_data_frame=FALSE)
chunked_array<- as.vector(nyctaxi[[5]])
.Internal(inspect(chunked_array))
#> @7fb218000000 14 REALSXP g0c7 [REF(4)] (len=14863778, tl=0) 0.75,5.9,4,4.7,0.6,...array<- as.vector(nyctaxi[[5]]$chunk(1))
.Internal(inspect(array))
#> @7fb20dc3a6e0 14 REALSXP g0c0 [REF(65535)] arrow::Array<double, NONULL> len=5738, Array=<0x7fb25d5080d8>#> @7fb20dc3a670 22 EXTPTRSXP g0c0 [REF(4)]

@jonkeane

Copy link
Copy Markdown
Member

And here's the report:

altvec-with-nulls.html.zip

@nealrichardson

Copy link
Copy Markdown
Member
  • multi-chunk arrays aren't (yet) supported

That's ARROW-13111. ARROW-13112 is for supporting other types. If I understand correctly, we're conceptually close on those since we're implementing the get_region and elt methods for integer and float here, just ("just"!) need to [something about templates] and do the same for other types and for ChunkedArrays using our existing conversion code.

@romainfrancois
romainfrancois deleted the ARROW-13164_altrep_with_nulls branch September 9, 2021 06:49
ViniciusSouzaRoque pushed a commit to s1mbi0se/arrow that referenced this pull request Oct 20, 2021
Closesapache#10730 from romainfrancois/ARROW-13164_altrep_with_nulls
Lead-authored-by: Romain Francois <romain@rstudio.com>
Co-authored-by: Romain François <romain@rstudio.com>
Signed-off-by: Neal Richardson <neal.p.richardson@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@romainfrancois@nealrichardson@ursabot@jonkeane@bkietz@pitrou