Skip to content
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

Merged
merged 3 commits into from
Jul 26, 2021

Conversation

DonJayamanne
Copy link
Contributor

This PR fixes #129212

@@ -27,6 +27,7 @@ export function getPreferredLanguage(metadata?: nbformat.INotebookMetadata) {
return translateKernelLanguageToMonaco(jupyterLanguage || defaultLanguage);
}

const textDecoder = new TextDecoder();
Copy link
Contributor Author

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') {
Copy link
Contributor Author

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), []);
Copy link
Contributor Author

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

Copy link
Member

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)

@DonJayamanne DonJayamanne changed the title Ensure ipynb serializer supports node environments Ensure ipynb serializer supports node environments and large # of outputs Jul 23, 2021
@DonJayamanne DonJayamanne requested a review from roblourens July 23, 2021 23:56
@DonJayamanne DonJayamanne marked this pull request as ready for review July 23, 2021 23:56
@weinand weinand assigned roblourens and unassigned weinand Jul 24, 2021
if (mime === CellOutputMimeTypes.error) {
const stringValue = textDecoder.decode(value.buffer.slice(value.byteOffset));
Copy link
Member

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.

Copy link
Member

@roblourens roblourens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@DonJayamanne DonJayamanne merged commit 198a555 into microsoft:main Jul 26, 2021
@DonJayamanne DonJayamanne deleted the fixIPynbSerializer branch July 26, 2021 16:55
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't save notebook because of maximum call stack size exceeded
4 participants