mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 00:59:03 +01:00
Transfer notebook output as VSBuffer (#130452)
* Transfer notebook output data as a VSBuffer This PR transfers notebook output as an VSBuffer instead of as a array of numbers. This significantly reduces the message size as well as the serialize/deserialize times To accomplish this, I've introduced a new `SerializableObjectWithBuffers` type. This specially marks rpc objects that contain VSBuffers. This is needed as our current RPC implementation can only efficently transfer VSBuffers that appears as top level arguments. The rpcProtocol now can also identify top level `SerializableObjectWithBuffers` arguments and ensure these are serialized more efficently. This is easier than trying to extract the `VSBuffer` proeprties to top level arguments. It also lets us easily support return types that may contain buffers * use SerializableObjectWithBuffers when dealing with (old) notebook controllers Co-authored-by: Johannes Rieken <johannes.rieken@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePa
|
||||
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
|
||||
import { INotebookExclusiveDocumentFilter, INotebookContributionData } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
|
||||
import type * as vscode from 'vscode';
|
||||
import { ExtHostCell, ExtHostNotebookDocument } from './extHostNotebookDocument';
|
||||
import { ExtHostNotebookEditor } from './extHostNotebookEditor';
|
||||
@@ -334,33 +335,33 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
});
|
||||
}
|
||||
|
||||
async $dataToNotebook(handle: number, bytes: VSBuffer, token: CancellationToken): Promise<NotebookDataDto> {
|
||||
async $dataToNotebook(handle: number, bytes: VSBuffer, token: CancellationToken): Promise<SerializableObjectWithBuffers<NotebookDataDto>> {
|
||||
const serializer = this._notebookSerializer.get(handle);
|
||||
if (!serializer) {
|
||||
throw new Error('NO serializer found');
|
||||
}
|
||||
const data = await serializer.deserializeNotebook(bytes.buffer, token);
|
||||
return typeConverters.NotebookData.from(data);
|
||||
return new SerializableObjectWithBuffers(typeConverters.NotebookData.from(data));
|
||||
}
|
||||
|
||||
async $notebookToData(handle: number, data: NotebookDataDto, token: CancellationToken): Promise<VSBuffer> {
|
||||
async $notebookToData(handle: number, data: SerializableObjectWithBuffers<NotebookDataDto>, token: CancellationToken): Promise<VSBuffer> {
|
||||
const serializer = this._notebookSerializer.get(handle);
|
||||
if (!serializer) {
|
||||
throw new Error('NO serializer found');
|
||||
}
|
||||
const bytes = await serializer.serializeNotebook(typeConverters.NotebookData.to(data), token);
|
||||
const bytes = await serializer.serializeNotebook(typeConverters.NotebookData.to(data.value), token);
|
||||
return VSBuffer.wrap(bytes);
|
||||
}
|
||||
|
||||
// --- open, save, saveAs, backup
|
||||
|
||||
async $openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken): Promise<NotebookDataDto> {
|
||||
async $openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken): Promise<SerializableObjectWithBuffers<NotebookDataDto>> {
|
||||
const { provider } = this._getProviderData(viewType);
|
||||
const data = await provider.openNotebook(URI.revive(uri), { backupId, untitledDocumentData: untitledDocumentData?.buffer }, token);
|
||||
return {
|
||||
return new SerializableObjectWithBuffers({
|
||||
metadata: data.metadata ?? Object.create(null),
|
||||
cells: data.cells.map(typeConverters.NotebookCellData.from),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async $saveNotebook(viewType: string, uri: UriComponents, token: CancellationToken): Promise<boolean> {
|
||||
@@ -411,10 +412,10 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
this._editors.set(editorId, editor);
|
||||
}
|
||||
|
||||
$acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta): void {
|
||||
$acceptDocumentAndEditorsDelta(delta: SerializableObjectWithBuffers<INotebookDocumentsAndEditorsDelta>): void {
|
||||
|
||||
if (delta.removedDocuments) {
|
||||
for (const uri of delta.removedDocuments) {
|
||||
if (delta.value.removedDocuments) {
|
||||
for (const uri of delta.value.removedDocuments) {
|
||||
const revivedUri = URI.revive(uri);
|
||||
const document = this._documents.get(revivedUri);
|
||||
|
||||
@@ -433,11 +434,11 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
}
|
||||
}
|
||||
|
||||
if (delta.addedDocuments) {
|
||||
if (delta.value.addedDocuments) {
|
||||
|
||||
const addedCellDocuments: IModelAddedData[] = [];
|
||||
|
||||
for (const modelData of delta.addedDocuments) {
|
||||
for (const modelData of delta.value.addedDocuments) {
|
||||
const uri = URI.revive(modelData.uri);
|
||||
|
||||
if (this._documents.has(uri)) {
|
||||
@@ -478,8 +479,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
}
|
||||
}
|
||||
|
||||
if (delta.addedEditors) {
|
||||
for (const editorModelData of delta.addedEditors) {
|
||||
if (delta.value.addedEditors) {
|
||||
for (const editorModelData of delta.value.addedEditors) {
|
||||
if (this._editors.has(editorModelData.id)) {
|
||||
return;
|
||||
}
|
||||
@@ -495,8 +496,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
|
||||
const removedEditors: ExtHostNotebookEditor[] = [];
|
||||
|
||||
if (delta.removedEditors) {
|
||||
for (const editorid of delta.removedEditors) {
|
||||
if (delta.value.removedEditors) {
|
||||
for (const editorid of delta.value.removedEditors) {
|
||||
const editor = this._editors.get(editorid);
|
||||
|
||||
if (editor) {
|
||||
@@ -511,8 +512,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
}
|
||||
}
|
||||
|
||||
if (delta.visibleEditors) {
|
||||
this._visibleNotebookEditors = delta.visibleEditors.map(id => this._editors.get(id)!).filter(editor => !!editor) as ExtHostNotebookEditor[];
|
||||
if (delta.value.visibleEditors) {
|
||||
this._visibleNotebookEditors = delta.value.visibleEditors.map(id => this._editors.get(id)!).filter(editor => !!editor) as ExtHostNotebookEditor[];
|
||||
const visibleEditorsSet = new Set<string>();
|
||||
this._visibleNotebookEditors.forEach(editor => visibleEditorsSet.add(editor.id));
|
||||
|
||||
@@ -525,13 +526,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
this._onDidChangeVisibleNotebookEditors.fire(this.visibleNotebookEditors);
|
||||
}
|
||||
|
||||
if (delta.newActiveEditor === null) {
|
||||
if (delta.value.newActiveEditor === null) {
|
||||
// clear active notebook as current active editor is non-notebook editor
|
||||
this._activeNotebookEditor = undefined;
|
||||
} else if (delta.newActiveEditor) {
|
||||
this._activeNotebookEditor = this._editors.get(delta.newActiveEditor);
|
||||
} else if (delta.value.newActiveEditor) {
|
||||
this._activeNotebookEditor = this._editors.get(delta.value.newActiveEditor);
|
||||
}
|
||||
if (delta.newActiveEditor !== undefined) {
|
||||
if (delta.value.newActiveEditor !== undefined) {
|
||||
this._onDidChangeActiveNotebookEditor.fire(this._activeNotebookEditor?.apiEditor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user