Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache for SVG tags? #54

Open
Elilif opened this issue Jan 1, 2024 · 2 comments
Open

Add cache for SVG tags? #54

Elilif opened this issue Jan 1, 2024 · 2 comments

Comments

@Elilif
Copy link
Contributor

Elilif commented Jan 1, 2024

I noticed that every time a new keyword(such as "TODO") is inserted, svg-tag-make (or similar functions) is called. I think this is unnecessary because the same parameters will always generate the same image. So is it possible to add a cache to use the cached image in the case of the same parameters?

For instance:

(defvar svg-tag-cache nil)

(defun svg-tag-make-with-cache (tag &rest args)
  (unless svg-tag-cache
    (setq svg-tag-cache (make-hash-table :test 'equal)))
  (with-memoization (gethash `(tag ,@args) svg-tag-cache)
    (apply #'svg-tag-make tag args)))

In my case, I found that when using SVG tags in the tab-bar or modeline, using caching significantly reduces resource consumption.

Is it worthwhile to create a PR?

@appetrosyan
Copy link

I'd say it's a useful optimisation.

@rougier
Copy link
Owner

rougier commented Jan 9, 2024

Totally agree and I'm doing such caching in other libraries that use svg-lib but I do it very badly compared to your code. So yes, a PR would be warmly welcome indeed. Can we do it for every tag functions or do you foresee some problems ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants