Clojure

Significantly improve compile time by reducing calls to Class.forName

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Completed
  • Affects Version/s: Release 1.7
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Patch:
    Code
  • Approval:
    Ok

Description

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
    21/Sep/14 2:08 PM
    2 kB
    Zach Tellman
  2. clj-1529-no-cache.diff
    27/Oct/14 4:30 PM
    1 kB
    Alex Miller
  3. clj-1529-no-cache-2.diff
    05/Nov/14 11:37 AM
    1 kB
    Alex Miller
  4. clj-1529-with-cache.diff
    27/Oct/14 4:30 PM
    5 kB
    Alex Miller
  5. maybe-class-cache.patch
    07/Oct/14 4:06 PM
    5 kB
    Alex Miller
  6. maybe-class-cache-2.patch
    24/Oct/14 3:01 PM
    4 kB
    Alex Miller
  1. clj-1529.png
    40 kB
    08/Oct/14 2:13 PM

Activity

People

Vote (28)
Watch (9)

Dates

  • Created:
    Updated:
    Resolved: