-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure ipynb serializer supports node environments and large # of outputs #129282
Conversation
@@ -27,6 +27,7 @@ export function getPreferredLanguage(metadata?: nbformat.INotebookMetadata) { | |||
return translateKernelLanguageToMonaco(jupyterLanguage || defaultLanguage); | |||
} | |||
|
|||
const textDecoder = new TextDecoder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need to keep creating this every single time, this should make a tiny bit of dfference, specially with larger output counts
@@ -108,8 +109,12 @@ function convertJupyterOutputToBuffer(mime: string, value: unknown): NotebookCel | |||
} 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. | |||
const data = Uint8Array.from(atob(value), c => c.charCodeAt(0)); | |||
return new NotebookCellOutputItem(data, mime); | |||
if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the issue where previously this part of the code would fail in desktop (node)
@@ -369,7 +374,7 @@ function convertStreamOutput(output: NotebookCellOutput): JupyterOutput { | |||
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) | |||
.reduceRight<string[]>((prev, curr) => (Array.isArray(curr) ? prev.concat(...curr) : prev.concat(curr)), []); | |||
.reduceRight<string[]>((prev, curr) => prev.concat(curr), []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the issue here #129212
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll recommend we stop using concat
completely. Filed separate issue and suggestions of improving the performance and memory usage of convertStreamOutput
#129370 (comment)
87b2401
to
754b1de
Compare
if (mime === CellOutputMimeTypes.error) { | ||
const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, the lines that call slice should just be passing the UIntArray, I will fix those when this is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR fixes #129212