Clojure

Fast keyword intern

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.7
  • Fix Version/s: None
  • Component/s: None
  • Environment:
    Mac OS X 10.9.4 / 2.6 GHz Intel Core i5 / 8 GB 1600 MHz DDR3
    java version "1.7.0_17"
    Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
  • Patch:
    Code
  • Approval:
    Triaged

Description

Keyword's intern(Symbol) method uses recursive invocation to get a valid keyword instance.I think it can be rewrite into a 'for loop'
to reduce method invocation cost.
So i developed this patch, and make some simple benchmark.Run the following command line three times after 'ant jar':

java -Xms64m -Xmx64m -cp test:clojure.jar clojure.main -e "(time (dotimes [n 10000000] (keyword (str n))))"

Before patched:

"Elapsed time: 27343.827 msecs"
"Elapsed time: 26172.653 msecs"
"Elapsed time: 25673.764 msecs"

After patched:

"Elapsed time: 24884.142 msecs"
"Elapsed time: 23933.423 msecs"
"Elapsed time: 25382.783 msecs"

It looks the patch make keyword's intern a little more fast.

The patch is attached and test.

Thanks.

P.S. I've signed the contributor agreement, and my email is killme2008@gmail.com .

Activity

Hide
Alex Miller added a comment -

Looks intriguing (and would be a nice change imo). I ran this on a json parsing benchmark I used for the keyword changes and saw ~3% improvement.

Show
Alex Miller added a comment - Looks intriguing (and would be a nice change imo). I ran this on a json parsing benchmark I used for the keyword changes and saw ~3% improvement.
Hide
dennis zhuang added a comment -

Updated the patch, remove the 'k == null' clause in for loop,it's not necessary.

Show
dennis zhuang added a comment - Updated the patch, remove the 'k == null' clause in for loop,it's not necessary.
Hide
Andy Fingerhut added a comment -

Dennis, while JIRA can handle multiple patches with the same name, it can be confusing for people discussing the patches, and for some scripts I have to evaluate them. Please consider giving the patches different names (e.g. with version numbers in them), or removing older ones if they are obsolete.

Show
Andy Fingerhut added a comment - Dennis, while JIRA can handle multiple patches with the same name, it can be confusing for people discussing the patches, and for some scripts I have to evaluate them. Please consider giving the patches different names (e.g. with version numbers in them), or removing older ones if they are obsolete.
Hide
dennis zhuang added a comment -

Hi,andy

Thank you for reminding me.I deleted the old patch.

Show
dennis zhuang added a comment - Hi,andy Thank you for reminding me.I deleted the old patch.
Hide
dennis zhuang added a comment -

I am glad to see it is helpful.I benchmark the patch with current master branch,it's fine too.

Show
dennis zhuang added a comment - I am glad to see it is helpful.I benchmark the patch with current master branch,it's fine too.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: