-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Perf improvements to the ipynb serializer #131035
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
Conversation
@@ -61,8 +69,19 @@ function sortOutputItemsBasedOnDisplayOrder(outputItems: NotebookCellOutputItem[ | |||
} | |||
return compareWith.startsWith(value); | |||
}; | |||
const indexOfMimeTypeA = orderOfMimeTypes.findIndex(mime => isMimeTypeMatch(outputItemA.mime, mime)); | |||
const indexOfMimeTypeB = orderOfMimeTypes.findIndex(mime => isMimeTypeMatch(outputItemB.mime, mime)); | |||
let indexOfMimeTypeA = orderOfMimeTypes.findIndex((mime) => isMimeTypeMatch(mime, outputItemA.mime)); |
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.
Added something that was fixed in Jupyter extension (some how this was missing here).
I've added the changes/fixes here along with the corresponding tests.
@@ -94,7 +94,7 @@ function translateCellDisplayOutput(output: NotebookCellOutput): JupyterOutput { | |||
case 'display_data': { | |||
result = { | |||
output_type: 'display_data', | |||
data: output.items.reduceRight((prev: any, 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.
Not sure why it was reduceRight
, it should be reduce
(fix everywhere else)
.reduceRight<string[]>((prev, curr) => prev.concat(curr), []); | ||
.forEach(value => { | ||
// Ensure each line is a seprate entry in an array (ending with \n). | ||
const lines = value.split('\n'); |
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.
Made the changes as per the comments here #129370 (comment)
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.
for the split, we do want to handle CRLF?
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 don't think we need to (this is how we used to do it & based on what I know this is what Jupyter also does, - code was borrowed from Jupyter)
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.
@rchiodo /cc
|
||
suite('Output Order', () => { | ||
test('Verify order of outputs', async () => { | ||
const dataAndExpectedOrder: { output: nbformat.IDisplayData; expectedMimeTypesOrder: string[] }[] = [ |
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.
Tests for a fix that was missing
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.
👏 for the multi line stream improvement, only a few suggestions of how to improve the sorting.
Regarding indentation detection, I like that we can drop the external dependency but not sure how confident we are with the behavior change.
.reduceRight<string[]>((prev, curr) => prev.concat(curr), []); | ||
.forEach(value => { | ||
// Ensure each line is a seprate entry in an array (ending with \n). | ||
const lines = value.split('\n'); |
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.
for the split, we do want to handle CRLF?
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.
It looks great! 🚢
This PR fixes #129370