jenkins-bot has submitted this change and it was merged.

Change subject: Quick optimisation to avoid containsComparableForSerialization
......................................................................


Quick optimisation to avoid containsComparableForSerialization

As that method makes expensive ve.compare calls, we can quickly
avoid most cases by testing AnnotationSet#contains first.

On page load this reduces the number of ve.compare calls on
[[:en:Argentina]] from ~6,000,000 to about ~2,000.

Also reduces ve.compare calls per backspace keystroke from
~300 to 2.

We can optimise this further, but this is a good simple start.

Bug: 52013
Change-Id: Ie3b4517fd13383c48acb64b3c4e82051c34e7484
---
M modules/ve/dm/ve.dm.Converter.js
1 file changed, 13 insertions(+), 3 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 5e2a520..fee0b11 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -76,7 +76,12 @@
        targetSetOpen = targetSet.clone();
        for ( i = 0, len = currentSet.getLength(); i < len; i++ ) {
                annotation = currentSet.get( i );
-               if ( !targetSetOpen.containsComparableForSerialization( 
annotation ) ) {
+               // containsComparableForSerialization is expensive,
+               // so do a simple contains check first
+               if (
+                       !targetSetOpen.contains( annotation ) &&
+                       !targetSetOpen.containsComparableForSerialization( 
annotation )
+               ) {
                        startClosingAt = i;
                        break;
                } else {
@@ -97,7 +102,12 @@
        // Open annotations as needed
        for ( i = 0, len = targetSet.getLength(); i < len; i++ ) {
                annotation = targetSet.get( i );
-               if ( !currentSetOpen.containsComparableForSerialization( 
annotation ) ) {
+               // containsComparableForSerialization is expensive,
+               // so do a simple contains check first
+               if (
+                       !currentSetOpen.contains( annotation ) &&
+                       !currentSetOpen.containsComparableForSerialization( 
annotation )
+               ) {
                        open( annotation );
                        // Add to currentClone
                        currentSet.push( annotation );
@@ -1203,7 +1213,7 @@
                                text = '';
                        }
                        // Close any remaining annotations
-                       ve.dm.Converter.openAndCloseAnnotations( 
annotationStack, new ve.dm.AnnotationSet(),
+                       ve.dm.Converter.openAndCloseAnnotations( 
annotationStack, new ve.dm.AnnotationSet( this.store ),
                                openAnnotation, closeAnnotation
                        );
                        // Put the annotated nodes in the DOM

-- 
To view, visit https://gerrit.wikimedia.org/r/76100
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3b4517fd13383c48acb64b3c4e82051c34e7484
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to