Commit fd818194 authored by Phil Hughes's avatar Phil Hughes

fixed web worker performance

[ci skip]
parent 3a1c3c5d
...@@ -35,7 +35,7 @@ export default { ...@@ -35,7 +35,7 @@ export default {
this.editor.createInstance(this.$el); this.editor.createInstance(this.$el);
}) })
.then(() => this.setupEditor()) .then(() => this.setupEditor())
.catch((e) => { throw e;flash('Error setting up monaco. Please try again.'); }); .catch(() => flash('Error setting up monaco. Please try again.'));
}, },
setupEditor() { setupEditor() {
if (!this.activeFile) return; if (!this.activeFile) return;
......
/* global monaco */ /* global monaco */
import DirtyDiffWorker from 'worker-loader!./worker.diff'; import { throttle } from 'underscore';
import DirtyDiffWorker from './diff_worker';
import Disposable from '../common/disposable'; import Disposable from '../common/disposable';
export const getDiffChangeType = (change) => { export const getDiffChangeType = (change) => {
...@@ -34,12 +35,14 @@ export default class DirtyDiffController { ...@@ -34,12 +35,14 @@ export default class DirtyDiffController {
this.modelManager = modelManager; this.modelManager = modelManager;
this.decorationsController = decorationsController; this.decorationsController = decorationsController;
this.dirtyDiffWorker = new DirtyDiffWorker(); this.dirtyDiffWorker = new DirtyDiffWorker();
this.throttledComputeDiff = throttle(this.computeDiff, 250);
this.decorate = this.decorate.bind(this);
this.dirtyDiffWorker.addEventListener('message', e => this.decorate(e)); this.dirtyDiffWorker.addEventListener('message', this.decorate);
} }
attachModel(model) { attachModel(model) {
model.onChange(() => this.computeDiff(model)); model.onChange(() => this.throttledComputeDiff(model));
} }
computeDiff(model) { computeDiff(model) {
...@@ -61,6 +64,8 @@ export default class DirtyDiffController { ...@@ -61,6 +64,8 @@ export default class DirtyDiffController {
dispose() { dispose() {
this.disposable.dispose(); this.disposable.dispose();
this.dirtyDiffWorker.removeEventListener('message', this.decorate);
this.dirtyDiffWorker.terminate(); this.dirtyDiffWorker.terminate();
} }
} }
import { diffLines } from 'diff'; import { diffLines } from 'diff';
// eslint-disable-next-line import/prefer-default-export
export const computeDiff = (originalContent, newContent) => { export const computeDiff = (originalContent, newContent) => {
const changes = diffLines(originalContent, newContent); const changes = diffLines(originalContent, newContent);
......
...@@ -116,6 +116,10 @@ var config = { ...@@ -116,6 +116,10 @@ var config = {
loader: 'url-loader', loader: 'url-loader',
options: { limit: 2048 }, options: { limit: 2048 },
}, },
{
test: /\_worker\.js$/,
loader: 'worker-loader',
},
{ {
test: /\.(worker(\.min)?\.js|pdf|bmpr)$/, test: /\.(worker(\.min)?\.js|pdf|bmpr)$/,
exclude: /node_modules/, exclude: /node_modules/,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment