Comments (4)
For some reason it looks like the expressions aren't compiled to the same bytecode.
Decompiled areduce:
public final class bench$fn__19404 extends AFunction
{
public static final Var const__0;
public static Object invokeStatic() {
final Object a__6487__auto__19406 = bench$fn__19404.const__0.getRawRoot();
final Object l__6488__auto__19407 = Reflector.invokeStaticMethod(RT.classForName("clojure.lang.RT"), "alength", new Object[] { a__6487__auto__19406 });
long idx = 0L;
long acc = 0L;
while (Numbers.lt(idx, l__6488__auto__19407)) {
final long n = RT.intCast(idx) + 1;
acc = ((long[])bench$fn__19404.const__0.getRawRoot())[RT.intCast(idx)];
idx = n;
}
return Numbers.num(acc);
}
@Override
public Object invoke() {
return invokeStatic();
}
static {
const__0 = RT.var("clj-fast.bench", "numarr");
}
}
decompiled defn
public final class bench$traverse_arr extends AFunction
{
public static Object invokeStatic(final Object arr) {
final Object a__6487__auto__19396 = arr;
final int l__6488__auto__19397 = ((long[])a__6487__auto__19396).length;
long idx = 0L;
Object acc = null;
while (idx < l__6488__auto__19397) {
final long n = RT.intCast(idx) + 1;
acc = Numbers.num(RT.aget((long[])arr, RT.intCast(idx)));
idx = n;
}
return acc;
}
@Override
public Object invoke(final Object arr) {
return invokeStatic(arr);
}
}
I think there's a slight risk of testing in the repl
from clj-fast.
I didn't think to decompile. Definitely different implementations; one goes through numbers ns (lt vs <), and even has a really round-about lookup for the long array (binding to const0 and doing the rawroot lookup). Very curious. Wonder why this doesn't happen in the defn...
from clj-fast.
Probably the compiler evaluates it differently than it does a dynamic form
from clj-fast.
Given what I've found here I'm closing this issue. Feel free to reopen it whenever you think is appropriate or with new findings.
from clj-fast.
Related Issues (20)
- Faster fast-merge HOT 47
- better memoize example HOT 13
- Better get-in behavior (maybe already implemented) HOT 6
- May not be in scope, but fast detection of set intersection
- static-merge HOT 2
- fast-case HOT 8
- fastrecord HOT 10
- Clojurescript support? HOT 2
- Operations on ordered collections (probing) can be faster HOT 6
- Array cloning performance diffs HOT 25
- faster mapv and others (reference) using iterators HOT 2
- FileNotFoundException when try to use clj-fast HOT 2
- Extend assoc-in to take multiple k-v pairs? HOT 4
- not-found arities of get and get-in HOT 2
- General inliner HOT 11
- JMH
- Improve documentation and guidance
- faster aset HOT 2
- Bug in update-many
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clj-fast.