You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by sjcorbett <gi...@git.apache.org> on 2015/05/13 00:37:12 UTC

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

GitHub user sjcorbett opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/641

    brooklyn.util.text.Strings adjustments

    Prompted by the chance observation in VisualVM that way too much CPU time was spent in `Strings.removeFromStart/End ` via `Exceptions.stripBoringPrefixes` and `PropagatedRuntimeException`. Please check a with careful eye.
    
    For more on the time complexity of `String.substring` see http://stackoverflow.com/questions/4679746/time-complexity-of-javas-substring and http://stackoverflow.com/questions/16123446/java-7-string-substring-complexity.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sjcorbett/incubator-brooklyn strings

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-brooklyn/pull/641.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #641
    
----
commit 3b4aca2119839b4a29872f7c8db71d69ad863451
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Date:   2015-05-12T18:16:32Z

    assert(actual, expected) in StringsTest

commit 5f7e5f99e7aea8363db3295cdabe94548b6d456e
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Date:   2015-05-12T19:21:11Z

    Deprecates removeFromStart/End(String, String...)
    
    The only uses of Start that give more than one prefix are the method's
    tests. There is only one use of End that may as well be removeAllFromEnd.

commit 1de76aa7998d008eb0c8b9c54a0cb6b556795389
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Date:   2015-05-12T19:26:57Z

    Strings.removeAllFromStart/End only call substring() once.
    
    Java 7 update 6 changed the cost of String.substring from O(1) to O(n).
    This commit changes the two removeAll methods to make one substring calls
    rather than one per match.

commit 625e8ac5c395f6ee64d43324223bf64f1ab55275
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Date:   2015-05-12T19:28:48Z

    Exceptions.stripBoringPrefixes calls removeAllFromStart once with all prefixes

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-brooklyn/pull/641


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by sjcorbett <gi...@git.apache.org>.
Github user sjcorbett commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/641#issuecomment-101986483
  
    By sheer chance I spent yesterday debugging an issue whose root cause turned out to lie in exactly the same area as this PR aims to address. Though the changes here are a minor improvement, they do not solve the root issue, which is a wildly inefficient `Exceptions.collapseText` implementation, creating millions of throwaway `PropagatedRuntimeExceptions`. I'll merge this but will make further adjustments later.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/641#discussion_r30204334
  
    --- Diff: utils/common/src/main/java/brooklyn/util/text/Strings.java ---
    @@ -136,26 +150,45 @@ public static String removeFromEnd(String string, String ...suffixes) {
             return string;
         }
     
    -    /** as removeFromEnd, but repeats until all such suffixes are gone */
    -    public static String removeAllFromEnd(String string, String ...suffixes) {
    +    /**
    +     * As removeFromEnd, but repeats until all such suffixes are gone
    +     */
    +    public static String removeAllFromEnd(String string, String... suffixes) {
    +        if (isEmpty(string)) return string;
    +        int index = string.length();
             boolean anotherLoopNeeded = true;
             while (anotherLoopNeeded) {
                 if (isEmpty(string)) return string;
    --- End diff --
    
    `isEmpty(string)` already checked above


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/641#discussion_r30218306
  
    --- Diff: utils/common/src/main/java/brooklyn/util/text/Strings.java ---
    @@ -136,26 +150,45 @@ public static String removeFromEnd(String string, String ...suffixes) {
             return string;
         }
     
    -    /** as removeFromEnd, but repeats until all such suffixes are gone */
    -    public static String removeAllFromEnd(String string, String ...suffixes) {
    +    /**
    +     * As removeFromEnd, but repeats until all such suffixes are gone
    +     */
    +    public static String removeAllFromEnd(String string, String... suffixes) {
    +        if (isEmpty(string)) return string;
    +        int index = string.length();
             boolean anotherLoopNeeded = true;
             while (anotherLoopNeeded) {
                 if (isEmpty(string)) return string;
    --- End diff --
    
    Yeah, but now `string` isn't modified so one check should be enough. I think that to keep the initial intent (to short circuit the loop if nothing is left of the string) the check should be replaced with `index == 0`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by sjcorbett <gi...@git.apache.org>.
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/641#discussion_r30218450
  
    --- Diff: utils/common/src/main/java/brooklyn/util/text/Strings.java ---
    @@ -136,26 +150,45 @@ public static String removeFromEnd(String string, String ...suffixes) {
             return string;
         }
     
    -    /** as removeFromEnd, but repeats until all such suffixes are gone */
    -    public static String removeAllFromEnd(String string, String ...suffixes) {
    +    /**
    +     * As removeFromEnd, but repeats until all such suffixes are gone
    +     */
    +    public static String removeAllFromEnd(String string, String... suffixes) {
    +        if (isEmpty(string)) return string;
    +        int index = string.length();
             boolean anotherLoopNeeded = true;
             while (anotherLoopNeeded) {
                 if (isEmpty(string)) return string;
    --- End diff --
    
    Good thinking.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/641#issuecomment-101527265
  
    Good to merge, only minor comments.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: brooklyn.util.text.Strings adjust...

Posted by sjcorbett <gi...@git.apache.org>.
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/641#discussion_r30211260
  
    --- Diff: utils/common/src/main/java/brooklyn/util/text/Strings.java ---
    @@ -136,26 +150,45 @@ public static String removeFromEnd(String string, String ...suffixes) {
             return string;
         }
     
    -    /** as removeFromEnd, but repeats until all such suffixes are gone */
    -    public static String removeAllFromEnd(String string, String ...suffixes) {
    +    /**
    +     * As removeFromEnd, but repeats until all such suffixes are gone
    +     */
    +    public static String removeAllFromEnd(String string, String... suffixes) {
    +        if (isEmpty(string)) return string;
    +        int index = string.length();
             boolean anotherLoopNeeded = true;
             while (anotherLoopNeeded) {
                 if (isEmpty(string)) return string;
    --- End diff --
    
    The first check is really for `string != null`, so that `.length()` doesn't throw an exception. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---