[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/racket-mode ba1047b100 1/3: Add very small MRU cache for p
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/racket-mode ba1047b100 1/3: Add very small MRU cache for path+anchor->string |
Date: |
Tue, 24 Sep 2024 10:01:18 -0400 (EDT) |
branch: elpa/racket-mode
commit ba1047b1002796d8dc55a6a735d334d776f977f6
Author: Greg Hendershott <git@greghendershott.com>
Commit: Greg Hendershott <git@greghendershott.com>
Add very small MRU cache for path+anchor->string
Although commit a41f849 greatly optimized fetching/massaging Scribble
HTML, a small MRU cache can still be worthwhile for eldoc access
patterns. People may move point among a small set of identifiers, for
example navigating within an s-expression. We can avoid repeating
recent work, and make the navigation even faster.
---
racket-scribble-anchor.el | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/racket-scribble-anchor.el b/racket-scribble-anchor.el
index 5e90a90126..9c928c8255 100644
--- a/racket-scribble-anchor.el
+++ b/racket-scribble-anchor.el
@@ -9,6 +9,7 @@
;; SPDX-License-Identifier: GPL-3.0-or-later
(require 'cl-macs)
+(require 'ring)
(require 'seq)
(require 'shr)
(require 'racket-back-end)
@@ -31,11 +32,29 @@
(setq buffer-read-only t)
(current-buffer))))))
+(defvar racket--path+anchor-ring (make-ring 16)
+ "A small MRU cache of the N most recent strings.
+Each ring item is (cons (cons path anchor) str).")
+
(defun racket--path+anchor->string (path anchor)
- "A wrapper for `racket--scribble-path+anchor-insert'."
- (with-temp-buffer
- (racket--scribble-path+anchor-insert path anchor)
- (buffer-string)))
+ "A wrapper for `racket--scribble-path+anchor-insert'.
+Uses `racket--path+anchor-cache'."
+ (pcase (seq-some (lambda (item)
+ (and (equal (car item) (cons path anchor))
+ item))
+ (ring-elements racket--path+anchor-ring))
+ ((and `(,_path+anchor . ,str) item)
+ ;; Re-insert as newest.
+ (ring-remove+insert+extend racket--path+anchor-ring item)
+ str)
+ (_
+ (let* ((str (with-temp-buffer
+ (racket--scribble-path+anchor-insert path anchor)
+ (buffer-string)))
+ (item (cons (cons path anchor) str)))
+ ;; Insert as newest; oldest discarded when ring full.
+ (ring-insert racket--path+anchor-ring item)
+ str))))
(defun racket--scribble-path+anchor-insert (path anchor)
(let* ((tramp-verbose 2) ;avoid excessive tramp messages