]> git.eshelyaron.com Git - emacs.git/commit
Use non-Lisp allocation for internal hash-table vectors
authorMattias EngdegÄrd <mattiase@acm.org>
Fri, 27 Oct 2023 20:15:09 +0000 (22:15 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 14 Jan 2024 15:15:40 +0000 (16:15 +0100)
commitcccf541c0bf61dcad360e2720c30d4e801303a22
tree076218eb997f9daa17cd1eb98fef4f459d0f6da4
parent8939b8f18112bd5caa064f000f86d5281c1a75fb
Use non-Lisp allocation for internal hash-table vectors

Using xmalloc for allocating these arrays is much cheaper than using
Lisp vectors since they are no longer marked or swept by the GC, and
deallocated much sooner.  This makes GC faster and less frequent, and
improves temporal locality.

Zero-sized tables use NULL for their (0-length) vectors except the
index vector which has size 1 and uses a shared constant static vector
since it cannot be modified anyway.  This makes creation and
destruction of zero-sized hash tables very fast; they consume no
memory outside the base object.

* src/lisp.h (struct Lisp_Hash_Table): Retype the index, next, hash
and key_and_value vectors from Lisp_Object to appropriately typed
arrays (although hash values are still stored as Lisp fixnums).  Add
explicit table_size and index_size members.  All users updated.
* src/alloc.c (gcstat): Add total_hash_table_bytes.
(hash_table_allocated_bytes): New.
(cleanup_vector): Free hash table vectors when sweeping
the object.
(hash_table_alloc_bytes, hash_table_free_bytes): New.
(sweep_vectors): Update gcstat.total_hash_table_bytes.
(total_bytes_of_live_objects): Use it.
(purecopy_hash_table): Adapt allocation of hash table vectors.
(process_mark_stack): No more Lisp slots in the struct to trace.
* src/fns.c (empty_hash_index_vector): New.
(allocate_hash_table): Allocate without automatically GCed slots.
(alloc_larger_vector): Remove.
(make_hash_table, copy_hash_table, maybe_resize_hash_table):
Adapt vector allocation and initialisation.
* src/pdumper.c (hash_table_freeze, hash_table_thaw, dump_hash_table)
(dump_hash_table_contents):
Adapt dumping and loading to field changes.

(cherry picked from commit fa5c07fc87d557e642fc325852e8d0c87a9c176e)
src/alloc.c
src/fns.c
src/lisp.h
src/pdumper.c
src/print.c