emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] caar/cadr/cdar/cddr


From: Samuel Bronson
Subject: Re: [RFC] caar/cadr/cdar/cddr
Date: Thu, 12 Jul 2012 21:27:06 -0400


On Jul 12, 2012, at 8:12 PM, Stefan Monnier wrote:

How widely?  I've always been leery about those functions, myself.

$ grep -nHR "(car (car (" lisp | wc -l
45
$ grep -nHR "(car (cdr (" lisp | wc -l
164
$ grep -nHR "(cdr (car (" lisp | wc -l
45
$ grep -nHR "(cdr (cdr (" lisp | wc -l
84

Static counts might not be related to dynamic counts and don't indicate
much either in terms of actual performance gains.

FWIW the current cXXr implementation using `defsubst' is not very
efficient because they're written in subr.el which does not use lexical
scoping, so the bytecodes that get inlined by the compiler include an
unneeded "varref x". So you'd already get better performance by simply
moving these definitions to a file using lexical-binding.

Hmm. I see what you mean:

(disassemble '(lambda (x) (caar (cadr x))) (current-buffer))

nil
byte code:
  args: (x)
0       varref    x
1       dup     
2       varbind   x
3       cdr     
4       car     
5       unbind    1
6       dup     
7       varbind   x
8       car     
9       car     
10      unbind    1
11      return  

Surely the bytecode compiler can be made to do better with this; it's currently much more efficient to use car and cdr directly:

(disassemble '(lambda (x) (car (car (car (cdr x))))) (current-buffer))
nil
byte code:
  args: (x)
0       varref    x
1       cdr     
2       car     
3       car     
4       car     
5       return  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]