Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-visit perf of letfn #480

Closed
borkdude opened this issue Dec 19, 2020 · 1 comment
Closed

Re-visit perf of letfn #480

borkdude opened this issue Dec 19, 2020 · 1 comment

Comments

@borkdude
Copy link
Collaborator

See #395

We could do the equivalent of something like this:

(defmacro letfn_ [fnspecs & body]
  (let [syms (map first fnspecs)]
    `(with-local-vars ~(vec (interleave syms (repeat nil)))
       ~@(map (fn [sym fn-spec]
                `(var-set ~sym (fn ~sym ~@(rest fn-spec)))) syms fnspecs)
       nil
       ~@body)))

Then we would need to implement with-local-vars first. See #383. If that doesn't perform the way it should, then we could re-implement it as a special form.

borkdude added a commit that referenced this issue Dec 20, 2020
borkdude added a commit that referenced this issue Dec 20, 2020
@borkdude
Copy link
Collaborator Author

Fixed:

$ time ./sci "(letfn [(a1 [n] (if (#{0 1} n) 1 (+ (a2 (- n 2)) (a3 (- n 1)))))
        (a2 [n] (a1 n))
        (a3 [n] (a1 n))]
  (a1 30))"
1346269
./sci    4.16s  user 0.10s system 99% cpu 4.266 total
$ time /usr/local/bin/joker -e "(letfn [(a1 [n] (if (#{0 1} n) 1 (+ (a2 (- n 2)) (a3 (- n 1)))))
        (a2 [n] (a1 n))
        (a3 [n] (a1 n))]
  (a1 30))"
1346269
/usr/local/bin/joker -e    7.41s  user 0.74s system 148% cpu 5.478 total

borkdude added a commit that referenced this issue Dec 20, 2020
borkdude added a commit that referenced this issue Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant