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

Significantly improve compile time by reducing calls to Class.forName


    • Type: Improvement
    • Status: Closed
    • Priority: Critical
    • Resolution: Completed
    • Affects versions: Release 1.7
    • Fix versions: Release 1.7
    • Approval:
    • Patch:


      Compilation speed has been a real problem for a number of my projects, especially Aleph [1], which in 1.6 takes 18 seconds to load. Recently I realized that Class.forName is being called repeatedly on symbols which are lexically bound. Hits on Class.forName are cached, but misses are allowed to go through each time, which translates into tens of thousands of calls after calling `(use 'aleph.http)`.

      Proposed: Avoid calling Class.forName() on non-namespaced symbols that do not contain "." or start with "[", don't map to a Class in the ns, and are names in the current local env. Also, adjust the ordering of checks in tagToClass to check for hints before checking for class.

      [Note that the latest variant of the patch moves the check from the original patch farther down in the logic to avoid changing the semantics. This still yields virtually all of the performance gains. See comments for details.]

      Patch: clj-1529-no-cache-2.diff

      Screened by: Stu Halloway. Note that for this change the patch ended up being so small it is easier follow the code than the prose description.

      [1] https://github.com/ztellman/aleph


        1. class-for-name.diff
          2 kB
        2. clj-1529.png
          40 kB
        3. clj-1529-no-cache.diff
          1 kB
        4. clj-1529-no-cache-2.diff
          1 kB
        5. clj-1529-with-cache.diff
          5 kB
        6. maybe-class-cache.patch
          5 kB
        7. maybe-class-cache-2.patch
          4 kB



            • Assignee:
              ztellman Zach Tellman
            • Votes:
              20 Vote for this issue
              7 Start watching this issue


              • Created: