[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: funcall consing
From: |
LdBeth |
Subject: |
Re: funcall consing |
Date: |
Fri, 31 Dec 2021 22:27:00 +0800 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.2 (x86_64-apple-darwin18.7.0) MULE/6.0 (HANACHIRUSATO) |
>>>>> In <87ee5tm422.fsf@logand.com>
>>>>> Tomas Hlavaty <tom@logand.com> wrote:
Tomas> Hi,
Tomas> in order to optimize some elisp code, I am trying to understand where my
Tomas> consing comes from. So far it looks like that my assumption about the
Tomas> cause of consing are wrong and that the cause of consing is funcall. Is
Tomas> that plausible? I am seeing similar results like this (lexical-binding,
Tomas> also byte compiled):
Tomas> (benchmark-run 10 (dotimes (i 100000) (1+ i)))
Tomas> ;;(2.720941123 40 1.7525918699999998)
Tomas> (let ((x (lambda (i) (1+ i)))) (benchmark-run 10 (dotimes (i 100000)
(funcall x i))))
Tomas> ;;(4.9373091140000005 80 3.4835688719999958)
Tomas> i.e. funcall conses a lot and introduces cca double performance penalty.
Tomas> Is that right or am I doing something wrong?
Tomas> Would it be possible to improve that?
Try this:
```
(defun bar () (benchmark-run 10 (dotimes (i 100000) (1+ i))))
(defun foo () (let ((x (lambda (i) (1+ i))))
(benchmark-run 10 (dotimes (i 100000) (funcall x i)))))
(byte-compile 'foo)
(byte-compile 'bar)
(foo)
(0.054734 0 0.0)
(bar)
(0.019939000000000002 0 0.0)
```