{"slug": "chatgpt-large-chat-lag-fix", "title": "Chatgpt large chat lag fix", "summary": "A developer created a userscript called \"ChatGPT Large Chat Performance\" that fixes lag in very large ChatGPT conversations. The script uses CSS containment and detachable turbo scrolling to make long chats less sluggish by hiding thread content during rapid scrolling and restoring it when scrolling stops.", "body_md": "| // ==UserScript== | |\n| // @name ChatGPT Large Chat Performance | |\n| // @namespace local.chatgpt.performance | |\n| // @version 0.4.0 | |\n| // @description Makes very large ChatGPT conversations less sluggish with CSS containment and detachable turbo scrolling. | |\n| // @match https://chatgpt.com/* | |\n| // @match https://chat.openai.com/* | |\n| // @run-at document-idle | |\n| // @grant none | |\n| // ==/UserScript== | |\n| (function () { | |\n| 'use strict'; | |\n| const STYLE_ID = 'tm-chatgpt-large-chat-performance-style'; | |\n| const HEIGHT_VAR = '--tm-cgpt-turn-height'; | |\n| const TURN_SELECTOR = '[data-turn-id-container]'; | |\n| const SCROLL_IDLE_MS = 180; | |\n| let enabled = true; | |\n| let root = null; | |\n| let ro = null; | |\n| let mo = null; | |\n| let scanTimer = 0; | |\n| let scrollIdleTimer = 0; | |\n| let parked = false; | |\n| let parkedNodes = []; | |\n| let placeholder = null; | |\n| const seen = new WeakSet(); | |\n| function addStyles() { | |\n| if (document.getElementById(STYLE_ID)) return; | |\n| const style = document.createElement('style'); | |\n| style.id = STYLE_ID; | |\n| style.textContent = ` | |\n| ${TURN_SELECTOR} { | |\n| content-visibility: auto !important; | |\n| contain: layout style paint !important; | |\n| contain-intrinsic-size: auto var(${HEIGHT_VAR}, 760px) !important; | |\n| } | |\n| .markdown, | |\n| .text-message, | |\n| pre, | |\n| code { | |\n| overflow-wrap: anywhere !important; | |\n| } | |\n| video, | |\n| canvas, | |\n| iframe { | |\n| content-visibility: auto !important; | |\n| contain: layout paint !important; | |\n| } | |\n| #tm-cgpt-thread-placeholder { | |\n| display: block !important; | |\n| contain: strict !important; | |\n| visibility: hidden !important; | |\n| pointer-events: none !important; | |\n| } | |\n| `; | |\n| document.documentElement.appendChild(style); | |\n| } | |\n| function findThreadScrollRoot() { | |\n| const thread = document.querySelector('#thread'); | |\n| for (let el = thread?.parentElement; el; el = el.parentElement) { | |\n| const style = getComputedStyle(el); | |\n| if (/(auto|scroll|overlay)/.test(style.overflowY) && el.scrollHeight > el.clientHeight + 200) { | |\n| return el; | |\n| } | |\n| } | |\n| return document.scrollingElement || document.documentElement; | |\n| } | |\n| function rememberHeight(entry) { | |\n| const height = Math.ceil(entry.borderBoxSize?.[0]?.blockSize || entry.contentRect.height); | |\n| if (height > 40) entry.target.style.setProperty(HEIGHT_VAR, `${height}px`); | |\n| } | |\n| function observeTurn(turn) { | |\n| if (seen.has(turn)) return; | |\n| seen.add(turn); | |\n| ro.observe(turn); | |\n| } | |\n| function scanTurns() { | |\n| if (!enabled || !ro) return; | |\n| document.querySelectorAll(TURN_SELECTOR).forEach(observeTurn); | |\n| } | |\n| function scheduleScan() { | |\n| clearTimeout(scanTimer); | |\n| scanTimer = window.setTimeout(scanTurns, 150); | |\n| } | |\n| function getThread() { | |\n| return document.querySelector('#thread'); | |\n| } | |\n| function parkThread() { | |\n| if (parked) return; | |\n| const thread = getThread(); | |\n| if (!thread || !thread.childNodes.length) return; | |\n| const height = Math.max(thread.scrollHeight, thread.getBoundingClientRect().height, 1000); | |\n| placeholder = document.createElement('div'); | |\n| placeholder.id = 'tm-cgpt-thread-placeholder'; | |\n| placeholder.style.minHeight = `${Math.ceil(height)}px`; | |\n| parkedNodes = [...thread.childNodes]; | |\n| thread.replaceChildren(placeholder); | |\n| thread.style.minHeight = `${Math.ceil(height)}px`; | |\n| parked = true; | |\n| } | |\n| function restoreThread() { | |\n| if (!parked) return; | |\n| const thread = getThread(); | |\n| if (thread) { | |\n| thread.replaceChildren(...parkedNodes); | |\n| thread.style.minHeight = ''; | |\n| } | |\n| parkedNodes = []; | |\n| placeholder = null; | |\n| parked = false; | |\n| scheduleScan(); | |\n| } | |\n| function onScroll() { | |\n| parkThread(); | |\n| clearTimeout(scrollIdleTimer); | |\n| scrollIdleTimer = window.setTimeout(restoreThread, SCROLL_IDLE_MS); | |\n| } | |\n| function start() { | |\n| stop(false); | |\n| enabled = true; | |\n| addStyles(); | |\n| root = findThreadScrollRoot(); | |\n| ro = new ResizeObserver((entries) => entries.forEach(rememberHeight)); | |\n| scanTurns(); | |\n| mo = new MutationObserver(scheduleScan); | |\n| mo.observe(document.body, { childList: true, subtree: true }); | |\n| root?.addEventListener('scroll', onScroll, { passive: true }); | |\n| } | |\n| function stop(removeStyles = true) { | |\n| root?.removeEventListener('scroll', onScroll); | |\n| ro?.disconnect(); | |\n| mo?.disconnect(); | |\n| root = null; | |\n| ro = null; | |\n| mo = null; | |\n| clearTimeout(scanTimer); | |\n| clearTimeout(scrollIdleTimer); | |\n| restoreThread(); | |\n| if (removeStyles) document.getElementById(STYLE_ID)?.remove(); | |\n| } | |\n| function toggle() { | |\n| enabled = !enabled; | |\n| if (enabled) start(); | |\n| else stop(); | |\n| console.info(`[ChatGPT Large Chat Performance] ${enabled ? 'enabled' : 'disabled'}`); | |\n| } | |\n| window.addEventListener('keydown', (event) => { | |\n| if (event.altKey && event.code === 'KeyV') toggle(); | |\n| }); | |\n| start(); | |\n| })(); |", "url": "https://wpnews.pro/news/chatgpt-large-chat-lag-fix", "canonical_source": "https://gist.github.com/divyam234/0ab9540475fd65f7f254b3b6d37a263b", "published_at": "2026-06-03 18:07:51+00:00", "updated_at": "2026-06-06 01:44:02.504520+00:00", "lang": "en", "topics": ["ai-tools", "ai-products", "large-language-models", "artificial-intelligence"], "entities": ["ChatGPT", "OpenAI"], "alternates": {"html": "https://wpnews.pro/news/chatgpt-large-chat-lag-fix", "markdown": "https://wpnews.pro/news/chatgpt-large-chat-lag-fix.md", "text": "https://wpnews.pro/news/chatgpt-large-chat-lag-fix.txt", "jsonld": "https://wpnews.pro/news/chatgpt-large-chat-lag-fix.jsonld"}}