SideBySide2: Batch updates to CodeMirror3 during onShowView
Colby recently observed opening files is sluggish. Digging into profile data shows CM3 doing multiple relayouts if its internal DOM during onShowView(), once for each method being invoked. Batch these together into an operation() call, allowing CM3 to buffer the updates and update its DOM only once. Conflicts: gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/SideBySide2.java Change-Id: Iefbc112a37016c4031515b4422a02368e5af16c1
This commit is contained in:
committed by
Michael Zhou
parent
769bb5446a
commit
9e45db10c4
@@ -231,17 +231,29 @@ public class SideBySide2 extends Screen {
|
||||
@Override
|
||||
public void onShowView() {
|
||||
super.onShowView();
|
||||
resizeCodeMirror();
|
||||
Window.enableScrolling(false);
|
||||
|
||||
cmA.setOption("viewportMargin", 10);
|
||||
cmB.setOption("viewportMargin", 10);
|
||||
final int height = getCodeMirrorHeight();
|
||||
onShowView(cmA, height);
|
||||
onShowView(cmB, height);
|
||||
diffTable.sidePanel.adjustGutters(cmB);
|
||||
cmB.setCursor(LineCharacter.create(0));
|
||||
cmB.focus();
|
||||
|
||||
prefetchNextFile();
|
||||
}
|
||||
|
||||
private void onShowView(final CodeMirror cm, final int height) {
|
||||
cm.operation(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.setHeight(height);
|
||||
cm.setOption("viewportMargin", 10);
|
||||
cm.refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onUnload() {
|
||||
super.onUnload();
|
||||
@@ -1240,16 +1252,18 @@ public class SideBySide2 extends Screen {
|
||||
}
|
||||
|
||||
void resizeCodeMirror() {
|
||||
int height = getCodeMirrorHeight();
|
||||
cmA.setHeight(height);
|
||||
cmB.setHeight(height);
|
||||
diffTable.sidePanel.adjustGutters(cmB);
|
||||
}
|
||||
|
||||
private int getCodeMirrorHeight() {
|
||||
int rest = Gerrit.getHeaderFooterHeight()
|
||||
+ header.getOffsetHeight()
|
||||
+ diffTable.getHeaderHeight()
|
||||
+ 10; // Estimate
|
||||
int h = Window.getClientHeight() - rest;
|
||||
cmA.setHeight(h);
|
||||
cmB.setHeight(h);
|
||||
cmA.refresh();
|
||||
cmB.refresh();
|
||||
diffTable.sidePanel.adjustGutters(cmB);
|
||||
+ 5; // Estimate
|
||||
return Window.getClientHeight() - rest;
|
||||
}
|
||||
|
||||
static void setHeightInPx(Element ele, double height) {
|
||||
|
||||
@@ -166,6 +166,12 @@ public class CodeMirror extends JavaScriptObject {
|
||||
this.state.oldViewportSize = lines;
|
||||
}-*/;
|
||||
|
||||
public final native void operation(Runnable thunk) /*-{
|
||||
this.operation(function() {
|
||||
thunk.@java.lang.Runnable::run()();
|
||||
});
|
||||
}-*/;
|
||||
|
||||
public final native void on(String event, Runnable thunk) /*-{
|
||||
this.on(event, $entry(function() {
|
||||
thunk.@java.lang.Runnable::run()();
|
||||
|
||||
Reference in New Issue
Block a user