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

Add BracketedSort a new, faster algorithm for partialsort and friends #52006

Merged
merged 41 commits into from
Nov 23, 2023

Commits on Oct 28, 2023

  1. add sample implementation

    Lilith Hafner authored and Lilith Hafner committed Oct 28, 2023
    Configuration menu
    Copy the full SHA
    9f4ad8b View commit details
    Browse the repository at this point in the history
  2. add fallback and remove instrumentation

    Lilith Hafner authored and Lilith Hafner committed Oct 28, 2023
    Configuration menu
    Copy the full SHA
    e47321f View commit details
    Browse the repository at this point in the history
  3. add a faster, non-allocating version

    Lilith Hafner authored and Lilith Hafner committed Oct 28, 2023
    Configuration menu
    Copy the full SHA
    c61e6c3 View commit details
    Browse the repository at this point in the history

Commits on Oct 29, 2023

  1. small tweaks

    Lilith Hafner authored and Lilith Hafner committed Oct 29, 2023
    Configuration menu
    Copy the full SHA
    9093cb9 View commit details
    Browse the repository at this point in the history
  2. add tests and support target ranges

    Lilith Hafner authored and Lilith Hafner committed Oct 29, 2023
    Configuration menu
    Copy the full SHA
    ca7bd59 View commit details
    Browse the repository at this point in the history
  3. Add tuning

    Lilith Hafner authored and Lilith Hafner committed Oct 29, 2023
    Configuration menu
    Copy the full SHA
    a170fc7 View commit details
    Browse the repository at this point in the history
  4. implement threshold

    Lilith Hafner authored and Lilith Hafner committed Oct 29, 2023
    Configuration menu
    Copy the full SHA
    8c6eff6 View commit details
    Browse the repository at this point in the history

Commits on Nov 2, 2023

  1. Merge branch 'master' into lh/fast-partialsort

    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    4a6fce7 View commit details
    Browse the repository at this point in the history
  2. add slow version to Julia

    This commit speeds up my_partialsort! to be faster than it was before, but partialsort! is slower than any version of my_partialsort!
    
    julia> using Random; Random.seed!(1); x = rand(1000); hash(x)
    0x13843e5a90ce1e51
    
    julia> @Btime partialsort!(copy($x), 500);
      3.838 μs (3 allocations: 7.88 KiB)
    
    julia> @Btime my_partialsort!(copy($x), 500);
      1.946 μs (3 allocations: 7.88 KiB)
    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    1f1fc3b View commit details
    Browse the repository at this point in the history
  3. fix some bugs and fiddle with optimization passess (specifically disa…

    …ble IEEE opt. because it makes the kernel slower)
    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    4aad01f View commit details
    Browse the repository at this point in the history
  4. a bit more fiddling. The remaining perforamnce gap is due to NaN safety

    julia> using Random; Random.seed!(1); x = rand(1000); hash(x)
    0x13843e5a90ce1e51
    
    julia> @Btime partialsort!(copy($x), 500);
      2.671 μs (3 allocations: 7.88 KiB)
    
    julia> @Btime my_partialsort!(copy($x), 500);
      2.000 μs (3 allocations: 7.88 KiB)
    
    julia> @Btime partialsort!(copy($x), 500, lt=<);
      1.733 μs (3 allocations: 7.88 KiB)
    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    8e66d4b View commit details
    Browse the repository at this point in the history
  5. revert whitespace change

    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    5d07ffe View commit details
    Browse the repository at this point in the history
  6. update comments and increase tries from 4 to 5

    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    0f81beb View commit details
    Browse the repository at this point in the history
  7. remove 'deleteme' development file

    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    e1df36e View commit details
    Browse the repository at this point in the history
  8. Merge branch 'master' into lh/fast-partialsort

    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    0ebef7e View commit details
    Browse the repository at this point in the history
  9. update docstring

    Lilith Hafner authored and Lilith Hafner committed Nov 2, 2023
    Configuration menu
    Copy the full SHA
    8003a0c View commit details
    Browse the repository at this point in the history

Commits on Nov 3, 2023

  1. support non-unit-range targets

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    8e933c3 View commit details
    Browse the repository at this point in the history
  2. bugfix TODO: add tests that catch this

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    76d2833 View commit details
    Browse the repository at this point in the history
  3. another bugfix (this one caught by CI)

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    847172e View commit details
    Browse the repository at this point in the history
  4. update invalid lt tests

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    5a85c03 View commit details
    Browse the repository at this point in the history
  5. add todo

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    86fc129 View commit details
    Browse the repository at this point in the history
  6. Tweak dispatch to avoid >100% regressions on 39 element arrays & opti…

    …mize scalar arithmetic to avoid >100% regression when taking fallback
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    a3a6c47 View commit details
    Browse the repository at this point in the history
  7. more performance characteristic tweaks (and a dynamic dispatch perfor…

    …mance bugfix)
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    bda1b6d View commit details
    Browse the repository at this point in the history
  8. use standard optimizations for recursive calls

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    b2e4529 View commit details
    Browse the repository at this point in the history
  9. cleanup, add comments, and admit weakness against inputs with duplica…

    …tes, and remove type instability in crit-fail path
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    fd8d967 View commit details
    Browse the repository at this point in the history
  10. make lots of duplicates non-pathological (still not great, but not te…

    …rrible)
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    8361184 View commit details
    Browse the repository at this point in the history
  11. fix some bugs (wow, we need better test coverage!) and add a dispatch…

    … short-circuit to avoid dispatch overhead
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    5d52194 View commit details
    Browse the repository at this point in the history
  12. change offset from .5 to .7 (helps a huge amount for small to medium …

    …sized input success rates)
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    6f8048f View commit details
    Browse the repository at this point in the history
  13. noting that running a hundred benchmarks doesn't fail a single trial,…

    … drop max trials to 3 and adjust comments
    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    d0a38a2 View commit details
    Browse the repository at this point in the history
  14. implement NFC todo that requires rebuilding Julia

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    52a6785 View commit details
    Browse the repository at this point in the history
  15. fix typo

    Lilith Hafner authored and Lilith Hafner committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    1d90487 View commit details
    Browse the repository at this point in the history

Commits on Nov 4, 2023

  1. check and document the invariant that makes the @inboundss safe

    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    83c9e27 View commit details
    Browse the repository at this point in the history
  2. fix some unimportant off by one errors that have been bugging me

    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    0b2b399 View commit details
    Browse the repository at this point in the history
  3. round less coarsely

    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    422a14b View commit details
    Browse the repository at this point in the history
  4. micro-refactor to use more code sharing

    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    ad82125 View commit details
    Browse the repository at this point in the history
  5. Avoid overflow and nfc refactor add comments, and variable rename for…

    … readability
    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    ccb5c99 View commit details
    Browse the repository at this point in the history
  6. randomize initial hash seed; use consistent recursive algorithms; add…

    … tests
    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    650c6a2 View commit details
    Browse the repository at this point in the history
  7. REVERT ME: revert the re-introduction of PartialQuickSort

    There are some pretty compelling reasons to use PartialQuickSort instead of ScratchQuickSort as a base case for BracketedSort.
    However, PartialQuickSort can segfault for invalid but seemingly innocuous lt functions.
    I don't want to talk about introducing segfaults to the default sorting algorithms or introducing a regression to PartialQuickSort in this PR
    Revert this commit it you want `partialsort!(::Vector{Int}, ::Int)` not to allocate.
    Lilith Hafner authored and Lilith Hafner committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    5c18e25 View commit details
    Browse the repository at this point in the history

Commits on Nov 5, 2023

  1. implement Oscar's suggestion to speed up heuristic computation

    Lilith Hafner authored and Lilith Hafner committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    5657e5f View commit details
    Browse the repository at this point in the history

Commits on Nov 6, 2023

  1. accept that invalid lt continues to work

    Lilith Hafner authored and Lilith Hafner committed Nov 6, 2023
    Configuration menu
    Copy the full SHA
    069c453 View commit details
    Browse the repository at this point in the history

Commits on Nov 22, 2023

  1. Configuration menu
    Copy the full SHA
    eb86ec5 View commit details
    Browse the repository at this point in the history