MichaelChirico commented on a change in pull request #24885: [SPARK-28040][R]
Add serialization for glue type
URL: https://github.com/apache/spark/pull/24885#discussion_r325521563
##########
File path: R/pkg/R/serialize.R
##########
@@ -71,18 +69,19 @@ writeObject <- function(con, object, writeType = TRUE) {
switch(serdeType,
NULL = writeVoid(con),
integer = writeInt(con, object),
+ glue = ,
Review comment:
I ran a quick benchmark... seems to me using implicit `switch` is about 40%
faster:
```
library(microbenchmark)
set.seed(38459)
options = sprintf(
"'%s'",
replicate(1e4, paste(sample(letters, sample(5L, 1L), TRUE), collapse = ''))
)
nrep = 1e7
timings = matrix(nrow = nrep, ncol = 3L)
for (ii in 1:nrep) {
nopt = sample(20L, 1L)
thisopt = sample(options, nopt)
thisval = paste0(1:nopt)
blank = sample(nopt, sample(nopt, 1L))
headval = sample(options, 1L)
fullexpr = parse(
text = sprintf("switch(%s, %s)", headval,
paste(sprintf('%s=%s', thisopt, thisval), collapse = ',
'))
)
blankexpr = parse(
text = sprintf("switch(%s, %s)", headval,
paste(sprintf('%s=%s', thisopt, `[<-`(thisval, blank,
'')),
collapse = ', '))
)
t0 = get_nanotime()
eval(fullexpr)
t1 = get_nanotime()
eval(blankexpr)
t2 = get_nanotime()
timings[ii, 1L] = nopt
timings[ii, 2L] = t1 - t0
timings[ii, 3L] = t2 - t1
}
```
with
```
summary(timings[ , 3L]/timings[ , 2L])
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
0.00 0.57 0.60 0.77 0.64 137407.00 227997
```
(I cut the benchmark short by 300K repetitions)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]