From a66280162f907a09be23922cc80ac352392adac6 Mon Sep 17 00:00:00 2001 From: Basil L. Contovounesios Date: Wed, 2 Nov 2022 03:50:38 +0200 Subject: Port interval trees to --enable-checking=structs Some names under the interval_* namespace were renamed under the itree_* namespace in commits: 0. f421b58db5 of 2022-10-19 "Prefix all itree.h type names with itree_". 1. 37a1145410 of 2022-10-19 "Rename all exported itree.h functions with the itree_ prefix" Further, some values still referenced in commentary were removed in commits: 2. 258e618364 of 2022-10-17 "Delete the itree_null sentinel node, use NULL everywhere." 3. 2c4a3910b3 of 2022-10-02 "itree: Use a single iterator object" * src/emacs.c (main): Allocate global itree iterator once and for all. * src/alloc.c (mark_overlay): * src/buffer.c (set_overlays_multibyte): * src/itree.c (itree_destroy): Update commentary. (interval_stack_ensure_space, itree_insert_gap): Prefer unsigned-to-unsigned comparisons over signed-to-unsigned. (interval_stack_push_flagged, interval_tree_insert) (interval_tree_contains, itree_iterator_start) (itree_iterator_finish, itree_iterator_next, itree_iterator_narrow): Improve assertions. (itree_init): Rename... (init_itree): ...to this, for consistency with other global init functions. (itree_create): Stop leaking a global iterator allocation on each call. (interval_tree_init): Complete renames of interval_tree -> itree_tree and interval_tree_clear -> itree_clear. (interval_tree_remove_fix): Fix indentation. * src/itree.h: Declare init_itree. (ITREE_FOREACH): Fix typo in commentary. * src/pdumper.c [CHECK_STRUCTS] (dump_interval_node): Use the correct name in the HASH condition and #error message. (dump_overlay, dump_buffer): Update HASH (bug#58975). --- src/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index f69c65dedc1..6862cf916fb 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6508,7 +6508,7 @@ mark_char_table (struct Lisp_Vector *ptr, enum pvec_type pvectype) static void mark_overlay (struct Lisp_Overlay *ov) { - /* We don't mark the `interval_node` object, because it is managed manually + /* We don't mark the `itree_node` object, because it is managed manually rather than by the GC. */ eassert (BASE_EQ (ov->interval->data, make_lisp_ptr (ov, Lisp_Vectorlike))); set_vectorlike_marked (&ov->header); -- cgit v1.2.1 From fb7f1864da4aa4c09756cfe47db6c56b4e87bd14 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 17 Nov 2022 17:00:22 -0500 Subject: itree.c: Make the iterator reentrant (bug#59183) Get rid of the global iterator object and instead allocate a separate iterator for every loop. This still uses the "duplicate iterator" code, including the old iterator which needs a stack, make ITREE_FOREACH a bit more expensive than we'd like. * src/itree.h (init_itree, forget_itree, itree_iterator_busy_p): Delete declarations. (itree_iterator_start): Add iterator arg and remove `line` and `file` args. (struct itree_iterator): Move from `itree.c`. Remove `line` and `file` fields. (ITREE_FOREACH): Stack allocate an iterator object and pass it to `itree_iterator_start`. * src/itree.c (struct itree_iterator): Move to itree.h. (iter): Delete global variable. (itree_iterator_create, init_itree, forget_itree, itree_iterator_busy_p): Delete functions. (itree_contains): Adjust assertion. (itree_iterator_finish): Deallocate the iterator's stack. (itree_iterator_start): Take the (uninitialized) iterator as argument. Allocate a fresh new stack. Remove `file` and `line` arguments. Don't check `running` any more since the iterator is not expected to be initialized at all. * src/eval.c (signal_or_quit): * src/alloc.c (garbage_collect): Don't check `itree_iterator_busy_p` any more. * src/emacs.c (main): No need to `init_itree` any more. (Fdump_emacs): No need to `forget_itree` any more. --- src/alloc.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 6862cf916fb..b9d12dff7e0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6279,11 +6279,6 @@ garbage_collect (void) image_prune_animation_caches (false); #endif - /* ELisp code run by `gc-post-hook' could result in itree iteration, - which must not happen while the itree is already busy. See - bug#58639. */ - eassert (!itree_iterator_busy_p ()); - if (!NILP (Vpost_gc_hook)) { specpdl_ref gc_count = inhibit_garbage_collection (); -- cgit v1.2.1 From 7b09ed28ba395030e5117344bb5b97b8ee4a8b40 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 20 Nov 2022 13:10:08 +0200 Subject: Advise against using too-high GC thresholds * doc/lispref/internals.texi (Garbage Collection): * src/alloc.c (syms_of_alloc) : Advise against enlarging the GC thresholds more than needed and for prolonged periods of time. --- src/alloc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index b9d12dff7e0..d3f696d5ade 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -7775,13 +7775,23 @@ allocated since the last garbage collection. All data types count. Garbage collection happens automatically only when `eval' is called. By binding this temporarily to a large number, you can effectively -prevent garbage collection during a part of the program. +prevent garbage collection during a part of the program. But be +sure to get back to the normal value soon enough, to avoid system-wide +memory pressure, and never use a too-high value for prolonged periods +of time. See also `gc-cons-percentage'. */); DEFVAR_LISP ("gc-cons-percentage", Vgc_cons_percentage, doc: /* Portion of the heap used for allocation. Garbage collection can happen automatically once this portion of the heap has been allocated since the last garbage collection. + +By binding this temporarily to a large number, you can effectively +prevent garbage collection during a part of the program. But be +sure to get back to the normal value soon enough, to avoid system-wide +memory pressure, and never use a too-high value for prolonged periods +of time. + If this portion is smaller than `gc-cons-threshold', this is ignored. */); Vgc_cons_percentage = make_float (0.1); -- cgit v1.2.1