[PR #2176] [MERGED] fix: lazy load js-tiktoken in prompts module #2016

Closed
opened 2026-03-02 12:00:12 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/karakeep-app/karakeep/pull/2176
Author: @MohamedBassem
Created: 11/27/2025
Status: Merged
Merged: 11/28/2025
Merged by: @MohamedBassem

Base: mainHead: claude/lazy-load-tiktoken-017UTNpJPTcMMQvNEBa1aFwo


📝 Commits (6)

  • 7c3e169 feat: lazy load tiktoken to reduce memory footprint
  • 44c6e2f fix: use createRequire for lazy tiktoken import in ES module
  • a226264 refactor: convert tiktoken lazy loading to async dynamic imports
  • 6b9c096 feat: add untruncated prompt builders for UI previews
  • 63f385d fix
  • 17616eb fix

📊 Changes

5 files changed (+110 additions, -37 deletions)

View changed files

📝 apps/web/components/settings/AISettings.tsx (+5 -6)
📝 apps/workers/workers/inference/summarize.ts (+1 -1)
📝 apps/workers/workers/inference/tagging.ts (+3 -3)
📝 packages/shared/prompts.ts (+100 -26)
📝 packages/trpc/routers/bookmarks.ts (+1 -1)

📄 Description

The js-tiktoken module loads a large encoding dictionary into memory immediately on import. This change defers the loading of the encoding until it's actually needed by using a lazy getter pattern.

This reduces memory usage for processes that import this module but don't actually use the token encoding functions.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/karakeep-app/karakeep/pull/2176 **Author:** [@MohamedBassem](https://github.com/MohamedBassem) **Created:** 11/27/2025 **Status:** ✅ Merged **Merged:** 11/28/2025 **Merged by:** [@MohamedBassem](https://github.com/MohamedBassem) **Base:** `main` ← **Head:** `claude/lazy-load-tiktoken-017UTNpJPTcMMQvNEBa1aFwo` --- ### 📝 Commits (6) - [`7c3e169`](https://github.com/karakeep-app/karakeep/commit/7c3e1695e4ba63f7a7359b69af3c096fb59eeb56) feat: lazy load tiktoken to reduce memory footprint - [`44c6e2f`](https://github.com/karakeep-app/karakeep/commit/44c6e2fe44f30eb4128b3f08be8daefe5ff30e49) fix: use createRequire for lazy tiktoken import in ES module - [`a226264`](https://github.com/karakeep-app/karakeep/commit/a22626448d89e199e214f701d208ce5ac8db696b) refactor: convert tiktoken lazy loading to async dynamic imports - [`6b9c096`](https://github.com/karakeep-app/karakeep/commit/6b9c096b2c148d690face3e3b4e6f8c520572eea) feat: add untruncated prompt builders for UI previews - [`63f385d`](https://github.com/karakeep-app/karakeep/commit/63f385deed6c06e105da70471bd29c0dd9dea290) fix - [`17616eb`](https://github.com/karakeep-app/karakeep/commit/17616eba694bb2005abf5cf400a198243c28f7d2) fix ### 📊 Changes **5 files changed** (+110 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `apps/web/components/settings/AISettings.tsx` (+5 -6) 📝 `apps/workers/workers/inference/summarize.ts` (+1 -1) 📝 `apps/workers/workers/inference/tagging.ts` (+3 -3) 📝 `packages/shared/prompts.ts` (+100 -26) 📝 `packages/trpc/routers/bookmarks.ts` (+1 -1) </details> ### 📄 Description The js-tiktoken module loads a large encoding dictionary into memory immediately on import. This change defers the loading of the encoding until it's actually needed by using a lazy getter pattern. This reduces memory usage for processes that import this module but don't actually use the token encoding functions. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 12:00:12 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/karakeep#2016
No description provided.