In perl.git, the branch smueller/hash_vtable has been created
<http://perl5.git.perl.org/perl.git/commitdiff/9cd309521371513749f3cb538ee3b93ba3b5f392?hp=0000000000000000000000000000000000000000>
at 9cd309521371513749f3cb538ee3b93ba3b5f392 (commit)
- Log -----------------------------------------------------------------
commit 9cd309521371513749f3cb538ee3b93ba3b5f392
Author: Steffen Mueller <[email protected]>
Date: Wed Jan 25 20:04:44 2017 +0100
Hash vtables: Move vtable testing hook
From newHV() to sv_upgrade() because that should now literally be the
place all hash allocations go through. (Famous last...)
M hv.h
M sv.c
commit 43ad480fdae705bdd21ac13b7d509720737c56f4
Author: Steffen Mueller <[email protected]>
Date: Wed Jan 25 20:04:27 2017 +0100
Hash vtables: exists shim
M hv.c
M hv_vtbl.c
M hv_vtbl.h
commit 76c9d9374400fd9a028d2878c989924d17d38fe4
Author: Steffen Mueller <[email protected]>
Date: Wed Jan 25 16:19:20 2017 +0100
Hash vtables: Add hooks for init/destroy
Also implements empty hooks in the mock example of the standard hash
implementation.
M hv.c
M hv_vtbl.c
M hv_vtbl.h
M sv.c
commit 729d1bde307a0598ef28b044026a97076c230e55
Author: Steffen Mueller <[email protected]>
Date: Wed Jan 25 16:16:09 2017 +0100
Hash vtables: Regen for previous commit
M embed.h
M proto.h
commit d4fb4677f03e888134357717b23c6d4c6377c8ce
Author: Steffen Mueller <[email protected]>
Date: Wed Jan 25 16:15:50 2017 +0100
Hash vtables: Fix warning: Introduce PERL_IN_HV_VTBL_C
M embed.fnc
M hv_vtbl.c
commit 8ce8806d6afcb4f3527b58f3c0d8f96e568842d3
Author: Steffen Mueller <[email protected]>
Date: Tue Jan 24 10:48:06 2017 +0100
Proof of principle hash vtables
This is a very partial implementation of having pluggable hashes by
(optionally) having magic-alike vtables which make all top level hash
operations pluggable.
At this point, this has all sorts of objectionable shortcuts. It also
means slowing down all operations by at least and extra compare+branch.
It also only does this for deletes right now because I'm just dabbling.
So in summary, this isn't much at all.
The reason why I'm playing with this is that if one were able to
specialize hash implementations (eg. perfect hashes or scanning small
lists for low-number-of-keys objects, having actual sets for huge
sets, having more compact "string only" (ie. no SV overhead) tables,
etc etc), I'd expect that one could gain a bunch.
Ultimately, this sort of thing is hindered by a great deal of things
such as the complete insanity of the hash API (way too many ways to do
things), the structure of the code (it's all shims to the same common
function - in an attempt to reduce code duplication), and the horror
that is MAGIC support. It's also decidedly hindered by my understanding
of the intricacies of the code base.
This doesn't solve the language design issue of how one would actually
make this accessible to Perl users. It'd be reasonably easy to have a
new keyword that takes an additional first parameter which indicates the
hash storage type (presumably as a constant string which can be
converted to a vtable at compile time using some kind of global lookup).
In terms of execution, this could generate either an OP that is similar
to pp_anonhash but has the type info on the stack, or it could literally
generate a pp_anonhash which abuses its op_targ as a way to store the
vtable pointer (PADOFFSET is an IV or UV which are big enough to hold a
pointer, but yuck.).
So I'm throwing this out there in case somebody (which includes my
future self) finds this intriguing enough to try to pursue further.
Right now, this commit includes a small change that redefines newHV to
ALWAYS assign a vtable (instead of defaulting to NULL, which falls
through to the normal hash implementation). It also ships a (partial)
vtable implementation which is meant to behave exactly the same way as
the normal implementation. This is to test that this whole scheme
actually work. As I was saying, right now in this commit, newHV is
hardwired to always set this "mock" vtable for testing.
M MANIFEST
M Makefile.SH
M embed.fnc
M embed.h
M hv.c
M hv.h
A hv_vtbl.c
A hv_vtbl.h
M proto.h
-----------------------------------------------------------------------
--
Perl5 Master Repository