GithubHelp home page GithubHelp logo

Comments (4)

bsless avatar bsless commented on June 11, 2024

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.

joinr avatar joinr commented on June 11, 2024

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.

bsless avatar bsless commented on June 11, 2024

Probably the compiler evaluates it differently than it does a dynamic form

from clj-fast.

bsless avatar bsless commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.