Optimizes long ChatGPT threads by virtualizing old conversation turns
A userscript for long ChatGPT conversations that reduces DOM load by virtualizing old conversation turns.
Instead of keeping the entire chat rendered at once, the script keeps only a small active window of recent turns in the DOM, removes older turns above the viewport, and restores them when you scroll back up.
This makes large chats more responsive and helps reduce lag in long threads.
The script:
conversation-turn sections in the DOMThis is designed for very long chats where rendering the full conversation causes performance issues.
The script is currently tuned to keep a very small live window:
MAX_TURNS = 6MIN_TURNS = 4PRUNE_BATCH = 1RESTORE_BATCH = 1This means the script tries to keep roughly the last 4 conversation turns active, while still preserving stable scrolling behavior.
Open the raw .user.js file in a browser with a userscript manager installed, such as Tampermonkey.
Example userscript managers:
Raw install URL:
https://raw.githubusercontent.com/9ghtX/ChatGPT-Optimizer/main/chatgpt-virtual-scroll.user.js
chatgpt-virtual-scroll.user.jsIf installed from the raw GitHub URL and the metadata block contains @updateURL and @downloadURL, your userscript manager should be able to detect updates automatically.
// ==UserScript==
// @name ChatGPT Virtual Scroll
// @namespace https://github.com/9ghtX/ChatGPT-Optimizer
// @version 2.2.0
// @description Optimizes long ChatGPT threads by virtualizing old conversation turns
// @author 9ghtX
// @match https://chatgpt.com/*
// @match https://chat.openai.com/*
// @grant none
// @downloadURL https://raw.githubusercontent.com/9ghtX/ChatGPT-Optimizer/main/chatgpt-virtual-scroll.user.js
// @updateURL https://raw.githubusercontent.com/9ghtX/ChatGPT-Optimizer/main/chatgpt-virtual-scroll.user.js
// ==/UserScript==
data-testid usage, the script may stop working correctlyIf needed, enable debug logs in the script:
const DEBUG = true;
This will print internal prune/restore events to the browser console.
For normal use or public release, it is recommended to keep:
const DEBUG = false;
The main tuning parameters are:
const MAX_TURNS = 6;
const MIN_TURNS = 4;
const PRUNE_BATCH = 1;
const RESTORE_BATCH = 1;
const RESTORE_ANCHOR_INDEX = 1;
const PRUNE_ANCHOR_INDEX = 3;
MAX_TURNS: maximum number of turns allowed before pruning startsMIN_TURNS: target minimum number of turns to keep after pruningPRUNE_BATCH: how many old turns to remove at onceRESTORE_BATCH: how many buffered turns to restore at onceRESTORE_ANCHOR_INDEX: restore when the anchor gets close to the top of the active windowPRUNE_ANCHOR_INDEX: prune when the anchor moves deep enough into the active windowChatGPT can become sluggish in very long threads because the page keeps too many rendered conversation elements alive at the same time.
This script is an attempt to reduce that cost without fully breaking normal scrolling behavior.
This project is licensed under the MIT License. See the LICENSE file for details.
Issues and suggestions are welcome.
If you find a broken layout case, include:
DEBUG is enabled