aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Armstrong2022-10-06 15:47:20 -0700
committerMatt Armstrong2022-10-07 09:38:49 -0700
commit780d3d8df2e9222a4643f0d0e9caf7628085d7bf (patch)
tree149fe9ba2fab959ad8329cd861f51b43a0aced38 /src
parentc0d5026321e5f5c5cfbf012f06d91fdead01eae4 (diff)
downloademacs-780d3d8df2e9222a4643f0d0e9caf7628085d7bf.tar.gz
emacs-780d3d8df2e9222a4643f0d0e9caf7628085d7bf.zip
; * src/itree.c: Add comment describing when noverlay is O(N)
Diffstat (limited to 'src')
-rw-r--r--src/itree.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/itree.c b/src/itree.c
index 79e39d6e2ab..d955c575390 100644
--- a/src/itree.c
+++ b/src/itree.c
@@ -62,6 +62,40 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
62 complexity of O(K*log(N)) for this operation, where K is the size 62 complexity of O(K*log(N)) for this operation, where K is the size
63 of the result set and N the size of the tree. 63 of the result set and N the size of the tree.
64 64
65 ==== FIXME: bug#58342 some important operations remain slow ===
66
67 The amortized costs of Emacs' previous-overlay-change and
68 next-overlay-change functions are O(N) with this data structure.
69 The root problem is that we only have an order for the BEG field,
70 but not the END. The previous/next overlay change operations need
71 to find the nearest point where there is *either* an interval BEG
72 or END point, but there is no efficient way to narrow the search
73 space over END postions.
74
75 Consider the case where next-overlay-change is called at POS, all
76 interval BEG positions are less than pos POS and all interval END
77 posistions are after. These END positions have no order, and so
78 *every* interval must be examined. This is at least O(N). The
79 previous-overlay-change case is similar. The root issue is that
80 the iterative "narrowing" approach is not guaranteed to reduce the
81 search space in logarithmic time, since END is not ordered in the
82 tree.
83
84 One might argue that the LIMIT value will do this narrowing, but
85 this narrowing is O(K*log(N)) where K is the size of the result
86 set. If we are interested in finding the node in a range with the
87 smallest END, we might have to examine all K nodes in that range.
88 In the case of the *-overlay-channge functions, K may well be equal
89 to N.
90
91 Ideally, a tree based data structure for overlays would have
92 O(log(N)) performance for previous-overlay-change and
93 next-overlay-change, as these are called in performance sensitive
94 situations such as redisplay. The only way I can think of
95 achieving this is by keeping one ordering by BEG and a separate
96 ordering by END, and then performing logic quite similar to the
97 current Emacs overlays-before and overlays-after lists.
98
65 ==== Adjusting intervals ==== 99 ==== Adjusting intervals ====
66 100
67 Since this data-structure will be used for overlays in an Emacs 101 Since this data-structure will be used for overlays in an Emacs