Change:
Issue Type: <bBug</bI was working on a notebook with lots of print output for debugging. 10min in, I could not save and got a notification of "Maximum call stack size exceeded". ! The kernel script was still running and printing hefty objects in a loop. I remember once crashing VS Code with long notebook output, so maybe this is related. Console log: Extension version: 2021.8. VS Code version: Code - Insiders 1.59.0-insider (, 2021-07-22T05:13:00.851Z) OS version: Darwin x64 20.5.0 Restricted Mode: No Remote OS version: Linux x64 5.10.25-linuxkit Fetching remote diagnostics for 'dev-container+7b22686f737450617468223a222f55736572732f64696769746172616c642f7265706f732f6465766469762d6d6574726963732d616e642d616e616c79736573222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d' timed out. <details<summarySystem Info</summary Fetching remote diagnostics for 'dev-container+7b22686f737450617468223a222f55736572732f64696769746172616c642f7265706f732f6465766469762d6d6574726963732d616e642d616e616c79736573222c2273657474696e6773223a7b22636f6e74657874223a226465736b746f702d6c696e7578227d7d' timed out. </details<details<summaryA/B Experiments</summary</details<!-- generated by issue reporter --
Saving while logging long print statements worked fine now.

Discussion:
return translateKernelLanguageToMonaco(jupyterLanguage || defaultLanguage); } <ins> const textDecoder = new TextDecoder(); </ins> function translateKernelLanguageToMonaco(language: string): string { language = language.toLowerCase(); if (language.length === 2 && language.endsWith('#')) {

} else if (mime.startsWith('image/') && typeof value === 'string' && mime !== 'image/svg+xml') { // Images in Jupyter are stored in base64 encoded format. // VS Code expects bytes when rendering images. <del> const data = Uint8Array.from(atob(value), c => c.charCodeAt(0)); return new NotebookCellOutputItem(data, mime); </del> <ins> if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') { return new NotebookCellOutputItem(Buffer.from(value, 'base64'), mime); } else { const data = Uint8Array.from(atob(value), c => c.charCodeAt(0)); return new NotebookCellOutputItem(data, mime); } </ins> } else if (typeof value === 'object' && value !== null && !Array.isArray(value)) { return NotebookCellOutputItem.text(JSON.stringify(value), mime); } else {

}; } const originalError: undefined | nbformat.IError = output.metadata?.originalError; <del> const value: Error = JSON.parse(new TextDecoder().decode(firstItem.data.buffer.slice(firstItem.data.byteOffset))); </del> <ins> const value: Error = JSON.parse(textDecoder.decode(firstItem.data.buffer.slice(firstItem.data.byteOffset))); </ins> return { output_type: 'error', ename: value.name,

const outputs = output.items .filter((opit) => opit.mime === CellOutputMimeTypes.stderr || opit.mime === CellOutputMimeTypes.stdout) .map((opit) => convertOutputMimeToJupyterOutput(opit.mime, opit.data as Uint8Array) as string) <del> .reduceRight<string[]>((prev, curr) => (Array.isArray(curr) ? prev.concat(...curr) : prev.concat(curr)), []); </del> <ins> .reduceRight<string[]>((prev, curr) => prev.concat(curr), []); </ins> const streamType = getOutputStreamType(output) || 'stdout';

return ''; } try { <del> const stringValue = new TextDecoder().decode(value.buffer.slice(value.byteOffset)); </del> if (mime === CellOutputMimeTypes.error) { <ins> const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset)); </ins> return JSON.parse(stringValue); } else if (mime.startsWith('text/') || textMimeTypes.includes(mime)) { <ins> const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset)); </ins> return splitMultilineString(stringValue); } else if (mime.startsWith('image/') && mime !== 'image/svg+xml') { // Images in Jupyter are stored in base64 encoded format. // VS Code expects bytes when rendering images. <del> // https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_1_%E2%80%93_escaping_the_string_before_encoding_it return btoa(encodeURIComponent(stringValue).replace(/%([0-9A-F]{2})/g, function (_match, p1) { return String.fromCharCode(Number.parseInt('0x' + p1)); })); </del> <ins> if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') { return Buffer.from(value).toString('base64'); } else { // https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_1_%E2%80%93_escaping_the_string_before_encoding_it const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset)); return btoa(encodeURIComponent(stringValue).replace(/%([0-9A-F]{2})/g, function (_match, p1) { return String.fromCharCode(Number.parseInt('0x' + p1)); })); } </ins> } else if (mime.toLowerCase().includes('json')) { <ins> const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset)); </ins> return stringValue.length > 0 ? JSON.parse(stringValue) : stringValue; } else { <ins> const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset)); </ins> return stringValue; } } catch (ex) {