Uploaded image for project: 'ClojureScript'
  1. CLJS-2066

Avoid analyzing named fn literal bodies twice

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: None
    • Fix versions: None
    • Labels:
    • Patch:
      Code

      Description

      In named fn literal like (fn foo [] 17), the body will be analyzed twice in order to leverage the self-name in a second analysis pass for further optimization.

      A consequence, though is exponential compilation complexity when you compile nested such forms. For example, in

      (fn foo [] (fn bar [] 17))
      

      The innermost body will be analyzed 4 times, with this doubling for each such nesting.

      One case where this kind of nesting occurs is in the macroexpansion of for involving multiple bindings. For example, the analysis of:

      (for [a nil b nil c nil d nil e nil f nil g nil h nil i nil j nil k nil l nil m nil] 1)
      

      can take on the order of 10 seconds, and with a fix it can be made to be instantaneous (as it is in Clojure).

        Attachments

          Activity

            People

            • Assignee:
              dnolen David Nolen
              Reporter:
              mfikes Mike Fikes
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: