Instantiate generic Object instead of generating random integer. #4

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Owner

abrooks commented Dec 20, 2013

Instantiating an Object is a bit over 4x faster and guaranteed not to collide.

user> (time (dotimes [x 10000000](rand-int Integer/MAX_VALUE)))
"Elapsed time: 2229.583833 msecs"

user> (time (dotimes x 10000000))
"Elapsed time: 530.217513 msecs"

@abrooks abrooks Instantiate generic Object instead of generating random integer.
Instantiating an Object is a bit over 4x faster and guaranteed not to collide.

user> (time (dotimes [x 10000000] (rand-int Integer/MAX_VALUE)))
"Elapsed time: 2229.583833 msecs"

user> (time (dotimes [x 10000000] (Object.)))
"Elapsed time: 530.217513 msecs"
798e12b
Owner

Chouser commented Dec 20, 2013

$ lein 1.5 test
java.lang.RuntimeException: Can't embed object in code, maybe print-dup not defined: java.lang.Object@90bb332

The problem is that currently the sigil is generated at macroexpand time and returned, so it has something the compiler can emit in such a way that when read later, it will be equal. It can do this with Long, but not with Object.

One alternative would be to generate the sigil value at runtime instead, but I don't know if that would be faster than using the already-generated Long.

Chouser closed this Dec 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment