You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "theigl (via GitHub)" <gi...@apache.org> on 2023/04/16 14:07:56 UTC

[GitHub] [wicket] theigl opened a new pull request, #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

theigl opened a new pull request, #579:
URL: https://github.com/apache/wicket/pull/579

   This PR initializes the string buffer for Strings#toMultilineMarkup to a capacity that should avoid resizing the buffer in most cases.
   
   https://issues.apache.org/jira/browse/WICKET-7047


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] solomax commented on a diff in pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "solomax (via GitHub)" <gi...@apache.org>.
solomax commented on code in PR #579:
URL: https://github.com/apache/wicket/pull/579#discussion_r1168071368


##########
wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java:
##########
@@ -1089,7 +1089,7 @@ public static CharSequence toMultilineMarkup(final CharSequence s)
 			return null;
 		}
 
-		final AppendingStringBuffer buffer = new AppendingStringBuffer();
+		final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (s.length() * 1.1));

Review Comment:
   This looks like black magic :)
   Maybe comment and/or meaningful constant name should be added? :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] theigl commented on a diff in pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "theigl (via GitHub)" <gi...@apache.org>.
theigl commented on code in PR #579:
URL: https://github.com/apache/wicket/pull/579#discussion_r1168181660


##########
wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java:
##########
@@ -1089,7 +1089,7 @@ public static CharSequence toMultilineMarkup(final CharSequence s)
 			return null;
 		}
 
-		final AppendingStringBuffer buffer = new AppendingStringBuffer();
+		final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (s.length() * 1.1));

Review Comment:
   We have the exact same logic in `Strings.escapeMarkup`:
   
   https://github.com/apache/wicket/blob/d51883862a448e26f8d973a24756ea7e03259de7/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java#L305
   
   A constant would have to be something like `ESTIMATED_OVERHEAD_OF_MULTILINE_MARKUP`. I think a comment would be better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] theigl merged pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "theigl (via GitHub)" <gi...@apache.org>.
theigl merged PR #579:
URL: https://github.com/apache/wicket/pull/579


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] theigl commented on a diff in pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "theigl (via GitHub)" <gi...@apache.org>.
theigl commented on code in PR #579:
URL: https://github.com/apache/wicket/pull/579#discussion_r1168193350


##########
wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java:
##########
@@ -1089,7 +1089,7 @@ public static CharSequence toMultilineMarkup(final CharSequence s)
 			return null;
 		}
 
-		final AppendingStringBuffer buffer = new AppendingStringBuffer();
+		final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (s.length() * 1.1));

Review Comment:
   I don't think so. The additional 10% should be enough to accommodate markup and escaping overhead in most cases. And if it isn't enough, the buffer is resized once. This is *much* better than resizing the buffer almost every time as it is now. Imho there is no need to configure or optimize this further.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] reiern70 commented on a diff in pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #579:
URL: https://github.com/apache/wicket/pull/579#discussion_r1168186263


##########
wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java:
##########
@@ -1089,7 +1089,7 @@ public static CharSequence toMultilineMarkup(final CharSequence s)
 			return null;
 		}
 
-		final AppendingStringBuffer buffer = new AppendingStringBuffer();
+		final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (s.length() * 1.1));

Review Comment:
   Would it make sense to have this "magic" in some setting?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] reiern70 commented on a diff in pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #579:
URL: https://github.com/apache/wicket/pull/579#discussion_r1168202846


##########
wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java:
##########
@@ -1089,7 +1089,7 @@ public static CharSequence toMultilineMarkup(final CharSequence s)
 			return null;
 		}
 
-		final AppendingStringBuffer buffer = new AppendingStringBuffer();
+		final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (s.length() * 1.1));

Review Comment:
   > I don't think so. The additional 10% should be enough to accommodate markup and escaping overhead in most cases. And if it isn't enough, the buffer is resized once. This is _much_ better than resizing the buffer almost every time as it is now. Imho there is no need to configure or optimize this further.
   
   Yes... I after I wrote my comment I looked at soucre code and I realized the 10% more should be enough. Maybe what we can have is a TenPercentMoreAppendingStringBuffer class?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [wicket] theigl commented on a diff in pull request #579: WICKET-7047 Improve initial buffer capacity for multiline-markup

Posted by "theigl (via GitHub)" <gi...@apache.org>.
theigl commented on code in PR #579:
URL: https://github.com/apache/wicket/pull/579#discussion_r1168248756


##########
wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java:
##########
@@ -1089,7 +1089,7 @@ public static CharSequence toMultilineMarkup(final CharSequence s)
 			return null;
 		}
 
-		final AppendingStringBuffer buffer = new AppendingStringBuffer();
+		final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (s.length() * 1.1));

Review Comment:
   I just realized that this has an adverse effect on short strings where the overhead of `<p></p>` is significantly more than 10%. It makes sense to set a minimum capacity for the buffer. Either via `Math.max((int)(len * 1.1), 16)` or by always adding the default capacity of 16 to the length.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org