Skip to content

Commit

Permalink
perf(render): optimize doc render (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer authored and yuanbin committed Mar 19, 2024
1 parent 77b96a4 commit 91a31ed
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/docs-ui/src/views/doc-canvas-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_VIEW_KEY, VIEWPORT_KEY } from '@univerjs/docs';
import type { IRender, IWheelEvent, RenderManagerService, Scene } from '@univerjs/engine-render';
import { Documents, EVENT_TYPE, IRenderManagerService, Layer, ScrollBar, Viewport } from '@univerjs/engine-render';
import { IEditorService } from '@univerjs/ui';
import { BehaviorSubject, takeUntil } from 'rxjs';

@OnLifecycle(LifecycleStages.Starting, DocCanvasView)
Expand All @@ -40,7 +41,8 @@ export class DocCanvasView extends RxDisposable {
constructor(
@IRenderManagerService private readonly _renderManagerService: RenderManagerService,
@IConfigService private readonly _configService: IConfigService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@IEditorService private readonly _editorService: IEditorService
) {
super();
this._initialize();
Expand Down Expand Up @@ -190,6 +192,8 @@ export class DocCanvasView extends RxDisposable {

scene.addObjects([documents], DOCS_COMPONENT_MAIN_LAYER_INDEX);

// scene.enableLayerCache(DOCS_COMPONENT_MAIN_LAYER_INDEX);
if (this._editorService.getEditor(documentModel.getUnitId()) == null) {
scene.enableLayerCache(DOCS_COMPONENT_MAIN_LAYER_INDEX);
}
}
}
40 changes: 40 additions & 0 deletions packages/engine-render/src/components/docs/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ export class Documents extends DocComponent {

const finalAngle = vertexAngle - centerAngle;

if (this._isSkipByDiffBounds(page, pageTop, pageLeft, bounds)) {
const { x, y } = this._drawLiquid.translatePage(
page,
this.pageLayoutType,
this.pageMarginLeft,
this.pageMarginTop
);
pageLeft += x;
pageTop += y;
continue;
}

this.onPageRenderObservable.notifyObservers({
page,
pageLeft,
Expand Down Expand Up @@ -538,6 +550,34 @@ export class Documents extends DocComponent {
});
}

private _isSkipByDiffBounds(page: IDocumentSkeletonPage, pageTop: number, pageLeft: number, bounds?: IViewportBound) {
if (bounds === null || bounds === undefined) {
return false;
}

const { pageWidth, pageHeight } = page;

const pageRight = pageLeft + pageWidth;

const pageBottom = pageTop + pageHeight;

const { left, top, right, bottom } = bounds.viewBound;

if (pageRight < left || pageBottom < top) {
return true;
}

if (pageLeft > right && pageWidth !== Number.POSITIVE_INFINITY) {
return true;
}

if (pageTop > bottom && pageHeight !== Number.POSITIVE_INFINITY) {
return true;
}

return false;
}

// private _addSkeletonChangeObserver(skeleton?: DocumentSkeleton) {
// if (!skeleton) {
// return;
Expand Down

0 comments on commit 91a31ed

Please sign in to comment.