Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/76110
Change subject: Further annotation optimisations
......................................................................
Further annotation optimisations
By using annotation indexes only we can avoid a lot of
ve.getHash calls. This reduces the number of getHash calls
on load of [[:en:Argentina]] from ~60,000 to ~2,000.
Bug: 52013
Change-Id: I0bc9aa8feea5f7e4e90a5fcd829de57cab803c15
---
M modules/ve/dm/ve.dm.AnnotationSet.js
M modules/ve/dm/ve.dm.Converter.js
2 files changed, 51 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/10/76110/1
diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js
b/modules/ve/dm/ve.dm.AnnotationSet.js
index 94e8e12..4bd5348 100644
--- a/modules/ve/dm/ve.dm.AnnotationSet.js
+++ b/modules/ve/dm/ve.dm.AnnotationSet.js
@@ -201,7 +201,18 @@
* @returns {number} Offset of annotation in the set, or -1 if annotation is
not in the set.
*/
ve.dm.AnnotationSet.prototype.offsetOf = function ( annotation ) {
- return ve.indexOf( this.store.indexOfHash( ve.getHash( annotation ) ),
this.getIndexes() );
+ return this.offsetOfIndex( this.store.indexOfHash( ve.getHash(
annotation ) ) );
+};
+
+/**
+ * Get the offset of a given annotation in the set by store index.
+ *
+ * @method
+ * @param {number} storeIndex Store index of annotation to search for
+ * @returns {number} Offset of annotation in the set, or -1 if annotation is
not in the set.
+ */
+ve.dm.AnnotationSet.prototype.offsetOfIndex = function ( storeIndex ) {
+ return ve.indexOf( storeIndex, this.getIndexes() );
};
/**
@@ -360,7 +371,16 @@
* @param {ve.dm.Annotation} annotation Annotation to add
*/
ve.dm.AnnotationSet.prototype.push = function ( annotation ) {
- var storeIndex = this.getStore().index( annotation );
+ this.pushIndex( this.getStore().index( annotation ) );
+};
+
+/**
+ * Add an annotation at the end of the set by store index.
+ *
+ * @method
+ * @param {number} storeIndex Store index of annotation to add
+ */
+ve.dm.AnnotationSet.prototype.pushIndex = function ( storeIndex ) {
this.storeIndexes.push( storeIndex );
};
@@ -382,6 +402,21 @@
};
/**
+ * Remove a given annotation from the set by store index.
+ *
+ * If the annotation isn't in the set, nothing happens.
+ *
+ * @method
+ * @param {number} storeIndex Store index of annotation to remove
+ */
+ve.dm.AnnotationSet.prototype.removeIndex = function ( storeIndex ) {
+ var offset = this.offsetOfIndex( storeIndex );
+ if ( offset !== -1 ) {
+ this.storeIndexes.splice( offset, 1 );
+ }
+};
+
+/**
* Remove a given annotation from the set.
*
* If the annotation isn't in the set, nothing happens.
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 15bc8c1..a0b0aa9 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -68,22 +68,22 @@
* @param {Function} close Callback called when an annotation is closed.
Passed a ve.dm.Annotation.
*/
ve.dm.Converter.openAndCloseAnnotations = function ( currentSet, targetSet,
open, close ) {
- var i, len, annotation, startClosingAt, currentSetOpen, targetSetOpen;
+ var i, len, index, startClosingAt, currentSetOpen, targetSetOpen;
// Close annotations as needed
// Go through annotationStack from bottom to top (low to high),
// and find the first annotation that's not in annotations.
targetSetOpen = targetSet.clone();
for ( i = 0, len = currentSet.getLength(); i < len; i++ ) {
- annotation = currentSet.get( i );
+ index = currentSet.getIndex( i );
if (
- !targetSetOpen.contains( annotation ) &&
- !targetSetOpen.containsComparableForSerialization(
annotation )
+ targetSetOpen.containsIndex( index ) ||
+ targetSetOpen.containsComparableForSerialization(
currentSet.get( i ) )
) {
+ targetSetOpen.removeIndex( index );
+ } else {
startClosingAt = i;
break;
- } else {
- targetSetOpen.remove( annotation );
}
}
if ( startClosingAt !== undefined ) {
@@ -99,19 +99,19 @@
currentSetOpen = currentSet.clone();
// Open annotations as needed
for ( i = 0, len = targetSet.getLength(); i < len; i++ ) {
- annotation = targetSet.get( i );
+ index = targetSet.getIndex( i );
if (
- !currentSetOpen.contains( annotation ) &&
- !currentSetOpen.containsComparableForSerialization(
annotation )
+ currentSetOpen.containsIndex( index ) ||
+ currentSetOpen.containsComparableForSerialization(
targetSet.get( i ) )
) {
- open( annotation );
- // Add to currentClone
- currentSet.push( annotation );
- } else {
// If an annotation is already open remove it from the
currentSetOpen list
// as it may exist multiple times in the targetSet, and
so may need to be
// opened again
- currentSetOpen.remove( annotation );
+ currentSetOpen.removeIndex( index );
+ } else {
+ open( targetSet.get( i ) );
+ // Add to currentClone
+ currentSet.pushIndex( index );
}
}
};
--
To view, visit https://gerrit.wikimedia.org/r/76110
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0bc9aa8feea5f7e4e90a5fcd829de57cab803c15
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits