all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: plists, alists, and hashtables
Date: Wed, 05 Aug 2015 23:11:41 +0200	[thread overview]
Message-ID: <87vbcto2ya.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 87oailbn8t.fsf@lifelogs.com

Ted Zlatanov <tzz@lifelogs.com> writes:

> I think these details are easily optimized at the C level. Clearly an
> alist is better as the *backend* hashtable implementation for up to 10,
> possibly up to 100 entries (depending on caching, pipelining, hashing
> function, and other factors). But the frontend presentation is what I'm
> concerned about. 

DUH!  What did I just do to write the benchmark?

So you're not discussing about hash-tables, but about how to provide
high level abstractions.  Well DUH, just program them! functions,
macros.

> I think a better reader syntax for hashtables would
> make them easier to write and read in code and would error out if they
> are malformed. That's an improvement over alists and plists I think.

And yes, if you had readtables and reader macros, also a reader macro.

Don't ask for a dictionary abtraction.  Ask for readtables and reader
macros!  So that you may implement your own syntax for your own
abstractions!



>
> PJB> The only advantage they have, is on speed of access in big dictionaries.
>
> PJB> But even when you need a O(1) access on a big dictionary, you will find
> PJB> you keep converting between hash-table and lists or vectors, of only to
> PJB> sort the entries out to present them to the user!
>
> That's no different than looping over alists and plists to collect and
> sort the entries, is it?

Well, for small dictionaries, (about 8 entries), it's still faster to
copy the keys from a-lists than from a hash-table.


> PJB> instead of a-list/p-lists, the only result you'd attain would be to
> PJB> slow down emacs. Run your own benchmark. On my computer, I notice
> PJB> that until the size of the dictionary reaches 20-30, a-lists are
> PJB> performing better than hash-table. (And even, I call assoc on set,
> PJB> while for a-list it is customary to just do acons, so inserting or
> PJB> reseting entries would be even much faster).
>
> Absolutely, but I mentioned already that this is easily fixed on the
> back end. I think it's clear that while hashtables *can* scale, alists
> and plists *can't* because their backend and frontend are the same.
> Hashtables are only accessible through an API, their backend is
> hidden.

Yes, you're asking about an abstraction and a nice API and syntax for
it.  

I'm saying ok, implement it, lisp is good for that. (It could be better
with reader macros).

I'm also saying, beware anyways, because even with adaptative data
structures abstracted away, you will aways have some (usage) complexity
coming up, from the fact that your abstract operations will have some
overhead and some time and space complexity that may not be what is the
best in some specific cases.



(let ((sizes '()))
 (mapatoms (lambda (s)
             (when (boundp s)
               (let ((table (symbol-value s)))
                 (when (hash-table-p table)
                   (push (hash-table-count table) sizes))))))
  (sort sizes '<))

Here are the results on three different emacs instances doing different
things: CL develoment with slime, erc, gnus:

--> (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 3 4 4 5 15 18 19 23 23 28 36 54 108 252 253 366 709 978 1013)
--> (0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 4 4 5 8 19 19 22 23 23 28 54 108 252 253 366 604 752 871 894 978)
--> (0 0 0 0 0 0 0 0 0 0 1 2 4 4 4 5 9 19 19 23 23 26 28 30 54 108 252 253 366 562 752 894 978 1638)

(length '(0 0 0 0 0 0 0 0 0 0 0))                    --> 11
(length '(1 2 4 4 4 5 9))                            -->  7
(length '(19 19 23 23 26 28 30))                     -->  7             
(length '(54 108 252 253 366 562 752 894 978 1638))  --> 10

So about half of those hash-table are too small, and should have been
implemented as a-lists, one quarter is around the break even, and only
one quarter should definitelhy be hash-tables.

You could improve this, by implementing a better data walker, here we
only look at the hash-tables directly bounds to variables.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


  parent reply	other threads:[~2015-08-05 21:11 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 21:42 How to iterate over properties in a plist? Marcin Borkowski
2015-07-31 22:18 ` Stefan Monnier
2015-07-31 22:29   ` Marcin Borkowski
2015-07-31 22:42     ` Dmitry Gutov
2015-08-01 13:34       ` Michael Heerdegen
     [not found]   ` <mailman.7705.1438381807.904.help-gnu-emacs@gnu.org>
2015-07-31 23:33     ` Pascal J. Bourguignon
2015-08-01 22:49       ` Stefan Monnier
     [not found]       ` <mailman.7750.1438469396.904.help-gnu-emacs@gnu.org>
2015-08-04 10:15         ` plists, alists, and hashtables (was: How to iterate over properties in a plist?) Ted Zlatanov
2015-08-04 10:29           ` Nicolas Petton
     [not found]           ` <mailman.7809.1438684158.904.help-gnu-emacs@gnu.org>
2015-08-04 11:23             ` plists, alists, and hashtables Ted Zlatanov
2015-08-05  4:36           ` plists, alists, and hashtables (was: How to iterate over properties in a plist?) Rusi
2015-08-05  6:12             ` plists, alists, and hashtables Pascal J. Bourguignon
2015-08-05  9:47               ` Ted Zlatanov
2015-08-05 12:20                 ` Rusi
2015-08-06 19:16                   ` Stefan Monnier
     [not found]                   ` <mailman.7892.1438888819.904.help-gnu-emacs@gnu.org>
2015-08-07 16:33                     ` Rusi
2015-08-05 17:24                 ` Pascal J. Bourguignon
2015-08-05 18:31                   ` Ted Zlatanov
2015-08-05 19:30                     ` Barry Margolin
2015-08-05 19:40                     ` Robert Thorpe
2015-08-05 21:11                     ` Pascal J. Bourguignon [this message]
2015-08-06 15:17                       ` Ted Zlatanov
2015-08-06 18:46                         ` Pascal J. Bourguignon
2015-08-06 20:19                           ` Drew Adams
2015-08-06 21:08                           ` Ted Zlatanov
2015-08-07  0:23                             ` Pascal J. Bourguignon
2015-08-06 19:35                         ` Stefan Monnier
2015-08-05 13:48               ` Drew Adams
2015-08-06 19:12           ` Stefan Monnier
     [not found]           ` <mailman.7890.1438888393.904.help-gnu-emacs@gnu.org>
2015-08-06 20:00             ` Pascal J. Bourguignon
2015-08-06 20:57             ` Ted Zlatanov
2015-08-06 21:10               ` Drew Adams
     [not found]               ` <mailman.7902.1438895429.904.help-gnu-emacs@gnu.org>
2015-08-06 21:15                 ` Ted Zlatanov
2015-08-06 21:31               ` Stefan Monnier
2015-08-07  1:53                 ` Ted Zlatanov
2015-08-07  7:34                   ` Pascal J. Bourguignon
2015-08-07 16:32                   ` Stefan Monnier
     [not found]                   ` <mailman.7941.1438965165.904.help-gnu-emacs@gnu.org>
2015-08-08  3:48                     ` Pascal J. Bourguignon
2015-08-08 13:42                       ` Stefan Monnier
2015-08-08 14:51                         ` Rusi
2015-08-07  0:08               ` Pascal J. Bourguignon
2015-08-07  2:14                 ` Ted Zlatanov
2015-08-07  7:53                   ` Pascal J. Bourguignon
2015-08-07 11:21                     ` Ted Zlatanov
2015-08-07 11:47                       ` Pascal J. Bourguignon
2015-08-07 17:21                         ` Ted Zlatanov
2015-08-07 19:21                           ` Stefan Monnier
     [not found]                           ` <mailman.7952.1438975314.904.help-gnu-emacs@gnu.org>
2015-08-08  3:52                             ` Pascal J. Bourguignon
2015-08-07 16:35                       ` Stefan Monnier
     [not found] <mailman.7856.1438803631.904.help-gnu-emacs@gnu.org>
2015-08-05 20:08 ` Ted Zlatanov
2015-08-05 20:45   ` Stefan Monnier
2015-08-05 21:36   ` Drew Adams
2015-08-05 21:41   ` Pascal J. Bourguignon
     [not found]   ` <mailman.7860.1438807554.904.help-gnu-emacs@gnu.org>
2015-08-06  1:32     ` Ted Zlatanov
     [not found]   ` <mailman.7862.1438810623.904.help-gnu-emacs@gnu.org>
2015-08-06  1:36     ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vbcto2ya.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.