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

perf(relocate): avoid redundant selector position computation #9644

Merged
merged 4 commits into from
Jul 22, 2024

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Jul 20, 2024

This PR cleans up selector position computation in relocate, which was computing selector positions sometimes more than once as well as looping through all parent table columns more than once. For relocate, in general we should be bound in the worst case by the number of columns returned by selector, not by the number of columns in the table. Previously we did this with the positions method (deleted in this PR), which would, for every selector used in relocate look at every column. Now, the positions are computed from the inverted _name_locs dict that lives on Schema objects.

Depends on #9641.

Closes #9111.

@cpcloud cpcloud added this to the 9.2 milestone Jul 20, 2024
@cpcloud cpcloud added internals Issues or PRs related to ibis's internal APIs performance Issues related to ibis's performance labels Jul 20, 2024
@cpcloud cpcloud force-pushed the relocate-perf branch 4 times, most recently from e2557f0 to 9dd7466 Compare July 20, 2024 12:22
@cpcloud
Copy link
Member Author

cpcloud commented Jul 20, 2024

Benchmarks for the 1000-column and 10000-column cases:

-------------------------------------------------------------------------------- benchmark 'test_wide_relocate[1000-after]': 2 tests ---------------------------------------------------------------------------------
Name (time in ms)                                      Min                 Max                Mean             StdDev              Median               IQR            Outliers      OPS            Rounds  Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[1000-after] (0001_49d345c)     183.7251 (7.51)     232.3225 (3.27)     194.2689 (7.37)     18.7335 (2.48)     187.5592 (7.41)     3.4540 (4.68)          1;1   5.1475 (0.14)          6           1
test_wide_relocate[1000-after] (NOW)               24.4517 (1.0)       71.0165 (1.0)       26.3717 (1.0)       7.5559 (1.0)       25.3283 (1.0)      0.7385 (1.0)           1;1  37.9195 (1.0)          37           1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------- benchmark 'test_wide_relocate[1000-before]': 2 tests --------------------------------------------------------------------------------
Name (time in ms)                                       Min                 Max                Mean             StdDev              Median               IQR            Outliers      OPS            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[1000-before] (0001_49d345c)     182.7077 (7.39)     233.1623 (3.37)     192.6081 (7.26)     19.8984 (2.87)     184.8687 (7.24)     1.9409 (6.34)          1;1   5.1919 (0.14)          6           1
test_wide_relocate[1000-before] (NOW)               24.7208 (1.0)       69.2196 (1.0)       26.5261 (1.0)       6.9297 (1.0)       25.5322 (1.0)      0.3059 (1.0)           1;4  37.6987 (1.0)          40           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------- benchmark 'test_wide_relocate[10000-after]': 2 tests ---------------------------------------------------------------------------
Name (time in s)                                      Min               Max              Mean            StdDev            Median               IQR            Outliers     OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[10000-after] (0001_49d345c)     2.1688 (4.59)     2.2448 (4.27)     2.1994 (4.41)     0.0314 (1.46)     2.1931 (4.37)     0.0505 (1.44)          1;0  0.4547 (0.23)          5           1
test_wide_relocate[10000-after] (NOW)              0.4720 (1.0)      0.5251 (1.0)      0.4984 (1.0)      0.0216 (1.0)      0.5023 (1.0)      0.0352 (1.0)           2;0  2.0065 (1.0)           5           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------- benchmark 'test_wide_relocate[10000-before]': 2 tests ----------------------------------------------------------------------------
Name (time in s)                                       Min               Max              Mean            StdDev            Median               IQR            Outliers     OPS            Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[10000-before] (0001_49d345c)     2.1376 (4.47)     2.1739 (4.17)     2.1603 (4.32)     0.0150 (1.0)      2.1675 (4.25)     0.0216 (1.0)           1;0  0.4629 (0.23)          5           1
test_wide_relocate[10000-before] (NOW)              0.4780 (1.0)      0.5212 (1.0)      0.5004 (1.0)      0.0187 (1.25)     0.5094 (1.0)      0.0308 (1.43)          2;0  1.9986 (1.0)           5           1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@cpcloud
Copy link
Member Author

cpcloud commented Jul 20, 2024

Managed to improve the performance even more by avoiding redundant binding when computing the front and back lists from before and after, respectively.

-------------------------------------------------------------------------------- benchmark 'test_wide_relocate[1000-after]': 2 tests ---------------------------------------------------------------------------------
Name (time in ms)                                      Min                 Max                Mean             StdDev              Median               IQR            Outliers      OPS            Rounds  Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[1000-after] (0001_49d345c)     183.7251 (9.23)     232.3225 (2.91)     194.2689 (8.79)     18.7335 (2.24)     187.5592 (9.17)     3.4540 (2.87)          1;1   5.1475 (0.11)          6           1
test_wide_relocate[1000-after] (NOW)               19.8958 (1.0)       79.7930 (1.0)       22.0961 (1.0)       8.3809 (1.0)       20.4647 (1.0)      1.2028 (1.0)           1;3  45.2568 (1.0)          50           1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------- benchmark 'test_wide_relocate[1000-before]': 2 tests --------------------------------------------------------------------------------
Name (time in ms)                                       Min                 Max                Mean             StdDev              Median               IQR            Outliers      OPS            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[1000-before] (0001_49d345c)     182.7077 (9.20)     233.1623 (3.47)     192.6081 (8.70)     19.8984 (2.17)     184.8687 (9.11)     1.9409 (18.03)         1;1   5.1919 (0.11)          6           1
test_wide_relocate[1000-before] (NOW)               19.8560 (1.0)       67.1513 (1.0)       22.1446 (1.0)       9.1812 (1.0)       20.2964 (1.0)      0.1076 (1.0)          2;11  45.1578 (1.0)          50           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------- benchmark 'test_wide_relocate[10000-after]': 2 tests ---------------------------------------------------------------------------
Name (time in s)                                      Min               Max              Mean            StdDev            Median               IQR            Outliers     OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[10000-after] (0001_49d345c)     2.1688 (10.62)    2.2448 (8.69)     2.1994 (9.32)     0.0314 (1.09)     2.1931 (8.62)     0.0505 (1.0)           1;0  0.4547 (0.11)          5           1
test_wide_relocate[10000-after] (NOW)              0.2042 (1.0)      0.2584 (1.0)      0.2359 (1.0)      0.0288 (1.0)      0.2543 (1.0)      0.0537 (1.06)          2;0  4.2387 (1.0)           5           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------- benchmark 'test_wide_relocate[10000-before]': 2 tests ----------------------------------------------------------------------------
Name (time in s)                                       Min               Max              Mean            StdDev            Median               IQR            Outliers     OPS            Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[10000-before] (0001_49d345c)     2.1376 (10.57)    2.1739 (8.26)     2.1603 (9.12)     0.0150 (1.0)      2.1675 (8.63)     0.0216 (1.0)           1;0  0.4629 (0.11)          5           1
test_wide_relocate[10000-before] (NOW)              0.2023 (1.0)      0.2631 (1.0)      0.2368 (1.0)      0.0293 (1.96)     0.2511 (1.0)      0.0539 (2.50)          1;0  4.2226 (1.0)           5           1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@cpcloud cpcloud added the refactor Issues or PRs related to refactoring the codebase label Jul 20, 2024
@cpcloud cpcloud force-pushed the relocate-perf branch 4 times, most recently from 5bbb660 to c237526 Compare July 20, 2024 18:18
@cpcloud
Copy link
Member Author

cpcloud commented Jul 20, 2024

Eked out even more (1.5-2x or so) by applying the same strategy as in #9641 re constructing ops.Project "by hand":

-------------------------------------------------------------------------------- benchmark 'test_wide_relocate[1000-after]': 2 tests ---------------------------------------------------------------------------------
Name (time in ms)                                      Min                 Max                Mean             StdDev              Median               IQR            Outliers      OPS            Rounds  Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[1000-after] (0001_01b6776)     172.3665 (10.93)    217.5964 (3.68)     180.6115 (10.71)    18.1246 (3.29)     173.3638 (10.70)    0.4927 (2.47)          1;2   5.5367 (0.09)          6           1
test_wide_relocate[1000-after] (NOW)               15.7689 (1.0)       59.1898 (1.0)       16.8609 (1.0)       5.5118 (1.0)       16.2039 (1.0)      0.1997 (1.0)           1;2  59.3087 (1.0)          61           1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------- benchmark 'test_wide_relocate[1000-before]': 2 tests --------------------------------------------------------------------------------
Name (time in ms)                                       Min                 Max                Mean             StdDev              Median               IQR            Outliers      OPS            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[1000-before] (0001_01b6776)     176.2376 (10.90)    224.8905 (13.30)    184.8559 (11.32)    19.6225 (190.92)   176.8815 (10.84)    1.6486 (18.54)         1;1   5.4096 (0.09)          6           1
test_wide_relocate[1000-before] (NOW)               16.1708 (1.0)       16.9154 (1.0)       16.3328 (1.0)       0.1028 (1.0)       16.3240 (1.0)      0.0889 (1.0)           9;1  61.2265 (1.0)          56           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------- benchmark 'test_wide_relocate[10000-after]': 2 tests ---------------------------------------------------------------------------
Name (time in s)                                      Min               Max              Mean            StdDev            Median               IQR            Outliers     OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[10000-after] (0001_01b6776)     1.9975 (12.02)    2.0972 (9.44)     2.0594 (10.33)    0.0382 (1.47)     2.0628 (9.70)     0.0442 (1.0)           1;0  0.4856 (0.10)          5           1
test_wide_relocate[10000-after] (NOW)              0.1661 (1.0)      0.2223 (1.0)      0.1994 (1.0)      0.0260 (1.0)      0.2127 (1.0)      0.0502 (1.13)          2;0  5.0147 (1.0)           6           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------- benchmark 'test_wide_relocate[10000-before]': 2 tests ----------------------------------------------------------------------------
Name (time in s)                                       Min               Max              Mean            StdDev            Median               IQR            Outliers     OPS            Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_wide_relocate[10000-before] (0001_01b6776)     2.0765 (12.55)    2.1235 (9.66)     2.0992 (10.72)    0.0183 (1.0)      2.0950 (9.91)     0.0274 (1.0)           2;0  0.4764 (0.09)          5           1
test_wide_relocate[10000-before] (NOW)              0.1655 (1.0)      0.2197 (1.0)      0.1958 (1.0)      0.0271 (1.48)     0.2115 (1.0)      0.0497 (1.82)          2;0  5.1066 (1.0)           5           1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@cpcloud cpcloud force-pushed the relocate-perf branch 3 times, most recently from b84aaa1 to 7723f6d Compare July 21, 2024 16:29
@cpcloud cpcloud requested review from jcrist and gforsyth July 22, 2024 11:38
Copy link
Member

@gforsyth gforsyth left a comment

Choose a reason for hiding this comment

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

🚀 (pending a rebase onto main)

@cpcloud cpcloud merged commit cd58214 into ibis-project:main Jul 22, 2024
95 checks passed
@cpcloud cpcloud deleted the relocate-perf branch July 22, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Issues or PRs related to ibis's internal APIs performance Issues related to ibis's performance refactor Issues or PRs related to refactoring the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

perf: Ibis slows down considerably for wider tables
2 participants