Uploaded image for project: 'Clojure'
  1. CLJ-1289

aset-* and aget perform poorly on multi-dimensional arrays even with type hints.

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects versions: Release 1.5
    • Fix versions: None
    • Environment:

      Clojure 1.5.1.

      Dependencies: criterium

    • Approval:
      Triaged
    • Patch:
      Code

      Description

      Here's a transcript of the behavior. I don't know for sure that reflection is being done, but the performance penalty (about 1300x) suggests it.

      user=> (use 'criterium.core)
      nil
      user=> (def b (make-array Double/TYPE 1000 1000))
      #'user/b
      user=> (quick-bench (aget ^"[[D" b 304 175))
      WARNING: Final GC required 3.5198021166354323 % of runtime
      WARNING: Final GC required 29.172288684474303 % of runtime
      Evaluation count : 63558 in 6 samples of 10593 calls.
                   Execution time mean : 9.457308 µs
          Execution time std-deviation : 126.220954 ns
         Execution time lower quantile : 9.344450 µs ( 2.5%)
         Execution time upper quantile : 9.629202 µs (97.5%)
                         Overhead used : 2.477107 ns
      

      One workaround is to use multiple agets.

      user=> (quick-bench (aget ^"[D" (aget ^"[[D" b 304) 175))
      WARNING: Final GC required 40.59820310542545 % of runtime
      Evaluation count : 62135436 in 6 samples of 10355906 calls.
                   Execution time mean : 6.999273 ns
          Execution time std-deviation : 0.112703 ns
         Execution time lower quantile : 6.817782 ns ( 2.5%)
         Execution time upper quantile : 7.113845 ns (97.5%)
                         Overhead used : 2.477107 ns
      

      Cause: The inlined version only applies to arity 2, and otherwise it reflects.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: