SillyTavern / SillyTavern

LLM Frontend for Power Users.
https://sillytavern.app
GNU Affero General Public License v3.0
13.69k stars 3.12k forks source link

Add disk cache for parsed character JSONs #3732

Closed Cohee1207 closed 4 weeks ago

Cohee1207 commented 1 month ago

Summary

Adds a data-directory backed cache for parsed character card JSONs via node-persist library, removing the need to constantly re-parse the PNG on /all API calls. This downs the load time of 20000 characters from 62s to s (~x30 boost), given the host device's disk is fast enough.

Notes

  1. Same as for memory cache, the data key is <path-to-file>-<modified-time>, which makes collisions or stale caches hardly (if ever) possible.
  2. This works in conjunction with memory cache, making further reloads even faster.
  3. The default state right now is ENABLED, but it's debatable. I don't see any potential downsides to that.
  4. Cached data is not directly editable. Editing a file would make the hash check fail. This is by design.
  5. The cache is validated on server startup to prune invalid records.

Copilot verbiage

This pull request introduces disk caching for character cards to enhance performance, particularly with large card libraries. The changes involve enabling disk caching in the configuration, updating the server setup to verify the disk cache, and modifying the character card parser to support asynchronous operations.

Performance improvements:

Asynchronous operations:

Disk caching implementation:

Checklist: