GNU bug report logs - #28362
26.0.50; [PATCH] gensym in core elisp

Previous Next

Package: emacs;

Reported by: Mark Oteiza <mvoteiza <at> udel.edu>

Date: Tue, 5 Sep 2017 17:12:01 UTC

Severity: wishlist

Tags: patch

Found in version 26.0.50

Done: Mark Oteiza <mvoteiza <at> udel.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Mark Oteiza <mvoteiza <at> udel.edu>
To: 28362 <at> debbugs.gnu.org
Subject: bug#28362: 26.0.50; [PATCH] gensym in core elisp
Date: Tue, 05 Sep 2017 13:11:23 -0400
[Message part 1 (text/plain, inline)]
Wishlist.

It would be nice to have gensym live in subr.el or C for the utility of
having uniquely named uninterned symbols.  It is helpful, for instance,
in the readability of macroexpansions of pcase and other macros that
generate many uninterned symbols of the same name.

As far as C vs Elisp--cl-gensym is about 10x slower than make-symbol,
but as far as macroexpansion goes, I get the impression gensym is not a
big contributing factor. Consider the following:

(defmacro case-lambda (&rest spec)
  "Return an arbitrary arity function."
  (declare (indent 0) (debug (&rest (pcase-QPAT body))))
  (let ((args (make-symbol "args")))
   `(lambda (&rest ,args)
      (pcase-exhaustive ,args ,@spec))))

(benchmark-run-compiled 1000
  (macroexpand-all
   '(case-lambda
      (`() t)
      (`(,x) (cons x 1))
      (`(,x ,y) (list x y 2))
      (`(,x ,y . ,z) (pcase-lambda (`(,cat ,dog))
                       (vector cat dog x y z 8)))))

The difference between the benchmark with make-symbol and make-symbol
fset to gensym is less than 1% (looking at profiler samples, interval
set to 1us).

I wrote a naïve gensym in C that is only about 1.5x to 2x faster than
cl-gensym (and incompatible because of the inaccessible counter). Patch
attached.

I also attached a patch putting gensym into subr.el.

I've tested both patches.

[gensym_alloc_c.patch (text/x-patch, attachment)]
[gensym.patch (text/x-patch, attachment)]

This bug report was last modified 7 years and 314 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.