Files
risuai/package.json
kwaroran cf22306c8c Refactor: Caching tokenize result (#805)
# PR Checklist
- [ ] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
- [ ] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
- [ ] Have you added type definitions?

# Improved performance

![image](https://github.com/user-attachments/assets/c7fa773f-afbb-4eb6-ac24-35c8451be33d)
The picture above was taken when I sent a chat.
As you can see, the encode function occupies **0.68 seconds** out of 1.8
seconds.
This is **36.5%** of sending time

![image](https://github.com/user-attachments/assets/cd2c4bde-556e-4151-82a9-030d27f2872a)
This is a picture taken after adding a caching function.
encode time Reduced from **0.68 seconds to 0.12 seconds, an improvement
of 27.2%**

Since configuration values are also used as key values in the hash
function,
it is guaranteed that **different results will be produced when the
configuration changes**.
I tested this myself by changing the bot settings

# Implementation
I added the `mnemonist` library to implement this. At first, I used
lru-cache, but that library recommended using this one if performance is
important.
It actually performed better too.

# Integrity Check

![image](https://github.com/user-attachments/assets/ae1272a8-ea95-47ef-85f5-c22dd9f34be7)
Lastly,
the encoding result calculated without caching when sending the first
chat,
the newly calculated value when sending the second chat, and
the result cached when sending the first chat were all the same.
2025-04-14 14:10:24 +09:00

131 lines
3.9 KiB
JSON

{
"name": "risuai",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"tauri": "tauri",
"buildsite": "vite build --outDir dist",
"updatePlugin": "tsc public/pluginApi.ts",
"runserver": "node server/node/server.cjs",
"sync": "node electron/sync",
"electron": "node electron/dist/electron"
},
"dependencies": {
"@adobe/css-tools": "4.3.2",
"@aws-crypto/sha256-js": "^5.2.0",
"@breezystack/lamejs": "^1.2.7",
"@browsermt/bergamot-translator": "^0.4.9",
"@capacitor/android": "^5.6.0",
"@capacitor/core": "^5.6.0",
"@capacitor/filesystem": "^5.2.0",
"@dqbd/tiktoken": "^1.0.7",
"@huggingface/jinja": "^0.2.2",
"@huggingface/transformers": "^3.1.1",
"@mlc-ai/web-tokenizers": "^0.1.2",
"@risuai/ccardlib": "^0.4.1",
"@smithy/protocol-http": "^3.0.12",
"@smithy/signature-v4": "^2.0.19",
"@tauri-apps/api": "2.0.0",
"@tauri-apps/plugin-deep-link": "~2",
"@tauri-apps/plugin-dialog": "~2",
"@tauri-apps/plugin-fs": "~2",
"@tauri-apps/plugin-http": "~2",
"@tauri-apps/plugin-os": "~2",
"@tauri-apps/plugin-process": "~2",
"@tauri-apps/plugin-shell": "~2",
"@tauri-apps/plugin-updater": "~2",
"@types/markdown-it": "^14.1.1",
"blueimp-md5": "^2.19.0",
"body-parser": "^1.20.2",
"buffer": "^6.0.3",
"codemirror": "^5.65.16",
"compression-streams-polyfill": "^0.1.7",
"core-js": "^3.35.0",
"cors": "^2.8.5",
"crc": "^4.3.2",
"diff": "^7.0.0",
"dompurify": "^3.0.8",
"eventsource-parser": "^1.1.2",
"exifr": "^7.1.3",
"express": "^4.18.2",
"fflate": "^0.8.1",
"gpt-3-encoder": "^1.1.4",
"gpt3-tokenizer": "^1.1.5",
"highlight.js": "^11.9.0",
"html-to-image": "^1.11.11",
"isomorphic-dompurify": "^1.13.0",
"jszip": "^3.10.1",
"libsodium-wrappers-sumo": "^0.7.13",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"lucide-svelte": "^0.292.0",
"markdown-it": "^14.1.0",
"ml-distance": "^4.0.1",
"mnemonist": "^0.40.3",
"mobile-drag-drop": "3.0.0-rc.0",
"msgpackr": "1.10.1",
"node-fetch": "2",
"node-html-parser": "^6.1.12",
"ollama": "^0.5.0",
"pdfjs-dist": "^4.0.379",
"peerjs": "^1.5.2",
"png-chunk-text": "^1.0.0",
"png-chunks-encode": "^1.0.0",
"png-chunks-extract": "^1.0.0",
"rfdc": "^1.4.1",
"rollup": "^3.29.4",
"showdown": "^2.1.0",
"sortablejs": "^1.15.2",
"streamsaver": "^2.0.6",
"sv": "^0.6.5",
"svelte-awesome-color-picker": "^3.1.0",
"three": "^0.154.0",
"tippy.js": "^6.3.7",
"uuid": "^9.0.1",
"wasmoon": "^1.16.0",
"wavefile": "^11.0.0",
"web-streams-polyfill": "^3.3.2"
},
"devDependencies": {
"@capacitor/assets": "^3.0.4",
"@capacitor/cli": "^5.6.0",
"@rollup/plugin-strip": "^3.0.4",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@swc/core": "1.5.7",
"@tailwindcss/typography": "^0.5.10",
"@tauri-apps/cli": "2.0.2",
"@tsconfig/svelte": "^3.0.0",
"@types/blueimp-md5": "^2.18.2",
"@types/codemirror": "^5.60.15",
"@types/diff": "^6.0.0",
"@types/dompurify": "^3.0.5",
"@types/libsodium-wrappers-sumo": "^0.7.8",
"@types/lodash": "^4.14.202",
"@types/lodash.isequal": "^4.5.8",
"@types/node": "^18.19.7",
"@types/showdown": "^2.0.6",
"@types/sortablejs": "^1.15.7",
"@types/streamsaver": "^2.0.4",
"@types/three": "^0.154.0",
"@types/uuid": "^9.0.7",
"@types/wicg-file-system-access": "^2020.9.8",
"autoprefixer": "^10.4.16",
"internal-ip": "^7.0.0",
"postcss": "^8.4.33",
"svelte": "^5.1.9",
"svelte-check": "^4.0.5",
"svelte-preprocess": "^6.0.0",
"tailwindcss": "^3.4.1",
"tslib": "^2.6.2",
"typescript": "^5.5.0",
"vite": "^5.4.4",
"vite-plugin-top-level-await": "1.4.1",
"vite-plugin-wasm": "3.3.0"
}
}