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

Support threading in joined column creation #2664

Merged
merged 5 commits into from
Mar 22, 2021
Merged

Support threading in joined column creation #2664

merged 5 commits into from
Mar 22, 2021

Conversation

bkamins
Copy link
Member

@bkamins bkamins commented Mar 19, 2021

A minor PR to speed up column creation in joins using threading.

Its major benefit is for left, right and outerjoins having many extra columns (and producing over 1_000_000 rows)

@bkamins bkamins added non-breaking The proposed change is not breaking performance labels Mar 19, 2021
@bkamins bkamins added this to the 1.0 milestone Mar 19, 2021
dfr_noon = joiner.dfr[right_ixs, Not(joiner.right_on)]

if VERSION >= v"1.4" && Threads.nthreads() > 1 && length(left_ixs) >= 1_000_000
dfl_task = Threads.@spawn joiner.dfl[left_ixs, :]
Copy link
Member Author

Choose a reason for hiding this comment

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

since getindex already uses threading this is only to ensure we are fast in case left and right table have very different processing times.

@@ -207,21 +215,35 @@ function compose_joined_table(joiner::DataFrameJoiner, kind::Symbol, makeunique:

@assert col_idx == ncol(joiner.dfl_on) + 1

for col in eachcol(dfl_noon)
Copy link
Member Author

Choose a reason for hiding this comment

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

I did not add threading for on-columns creation as in practice I expect that on-columns are minority of created columns and I avoid adding too much boilerplate code this way.

@bkamins
Copy link
Member Author

bkamins commented Mar 19, 2021

Example run.

Setup:

julia> Random.seed!(1234);

julia> df1 = sort!(DataFrame(rand(10^7, 10), :auto));

julia> df2 = sort!(DataFrame(rand(10^7, 10), :auto));

Execution on main:

julia> @benchmark outerjoin($df1, $df2, on=:x1, renamecols="left"=>"right")
BenchmarkTools.Trial: 
  memory estimate:  3.47 GiB
  allocs estimate:  479
  --------------
  minimum time:     2.890 s (27.14% GC)
  median time:      2.938 s (28.04% GC)
  mean time:        2.938 s (28.04% GC)
  maximum time:     2.986 s (28.92% GC)
  --------------
  samples:          2
  evals/sample:     1

Execution on this PR:

julia> @benchmark outerjoin($df1, $df2, on=:x1, renamecols="left"=>"right")
BenchmarkTools.Trial: 
  memory estimate:  3.47 GiB
  allocs estimate:  636
  --------------
  minimum time:     1.380 s (7.04% GC)
  median time:      1.632 s (19.31% GC)
  mean time:        1.640 s (18.85% GC)
  maximum time:     1.915 s (23.12% GC)
  --------------
  samples:          4
  evals/sample:     1

(using 8 threads in both cases)

@bkamins bkamins requested a review from nalimilan March 20, 2021 19:05
Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

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

Cool! I just wish we could find a way to avoid putting if checks everywhere in the long term.

end
@assert col_idx == ncol(joiner.dfl) + 1
for col in eachcol(dfr_noon)
let cols_i = col_idx
Copy link
Member

Choose a reason for hiding this comment

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

Why do you use let here but not above?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right - let is not needed, as just writing cols_i = col_idx will ensure we get a new binding for cols_i. I will change this.

Comment on lines 277 to 278
function _noon_compose_helper(cols, similar_col, cols_i, col, target_nrow,
side_ixs, offset, sideonly_ixs, tocopy)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add types to the signature? Maybe also add a ! at the end of the function name.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK - fixed

@bkamins
Copy link
Member Author

bkamins commented Mar 20, 2021

find a way to avoid putting if checks everywhere in the long term.

When we stop supporting Julia 1.0 it will be possible to significantly simplify the codes.

@bkamins bkamins merged commit 7564352 into main Mar 22, 2021
@bkamins bkamins deleted the join_threading branch March 22, 2021 09:09
@bkamins
Copy link
Member Author

bkamins commented Mar 22, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-breaking The proposed change is not breaking performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants