[jira] Created: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
Validate: add message parameter construction via elllipsis notation to speed up processing
------------------------------------------------------------------------------------------

                 Key: LANG-508
                 URL: https://issues.apache.org/jira/browse/LANG-508
             Project: Commons Lang
          Issue Type: Improvement
    Affects Versions: 2.4
            Reporter: Mark Struberg
             Fix For: 3.0


Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.

A typical usecase currently is:

{noformat}
Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
{noformat}
So all the string operations get executed regardless if the validation fails or not.

This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
{noformat}
Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
{noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Struberg updated LANG-508:
-------------------------------

    Attachment: LANG-508.patch

Patch which introduces new variants of all validate functions in the form of e.g.

{noformat}
public static void notNull(Object object, Object... msgObjects);
{noformat}

The commit is also available my github repo:

http://github.com/struberg/commons-lang/commit/ed8515f63290eba6e38ff5b79772e87b27dde32b

TBD: need to cleanup my JUnit tests, then I'll add those too soon

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12725486#action_12725486 ]

Henri Yandell commented on LANG-508:
------------------------------------

I'm uncomfortable with dropping the String message from the API.

notNull(Object, String, Object...) however seems fine.

I'm also wondering if there's any reason to keep notNull(Object, Object...) as a general API, or if messages should be mandatory.

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12725544#action_12725544 ]

Mark Struberg commented on LANG-508:
------------------------------------

Henri, thanks for reviewing!

Actually I didn't drop the String messages, and also didn't drop the 'more specialised' variants like isTrue(boolean expression, String message, double value) for keeping binary compatibility.

See here for the resulting code (same commit as above, but without diffs):
http://github.com/struberg/commons-lang/blob/ed8515f63290eba6e38ff5b79772e87b27dde32b/src/java/org/apache/commons/lang/Validate.java

The only thing I did to them is to also use the private getMessage function internally instead of the original simple string concatenation.

There are still a few things to clarify, as you can see in my '//X TODO' comments like in the noNullElements function. But those are easy ones to fix.

txs and LieGrue,
strub


> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12782748#action_12782748 ]

Paul Benedict commented on LANG-508:
------------------------------------

If we want to implement LANG-508 (Validate: add message parameter construction via elllipsis notation to speed up processing), I am really concerned with the many overloaded versions of #validIndex() and #notEmpty() that solely differ by static argument type: Collection, Object, Object[], CharSequence, etc.

Because var-args instantiate a new Object[], it won't be possible to easily create one-argument optimized overloaded versions to prevent the creation. Such as:
public static <T> T[] notEmpty(Object array, String message, Object var1);
public static <T> T[] notEmpty(Object array, String message, Object var1, Object var2);
public static <T> T[] notEmpty(Object array, String message, Object var1, Object var2, Object var3);
public static <T> T[] notEmpty(Object array, String message, Object var1, Object var2, Object var3, Object... vars);

I am following the good advice on Joshua Bloch on this one. It's item #42 in his Effective Java book.

I want to eliminate the overloaded versions by type and check those types using instanceof instead. Thoughts?

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12783363#action_12783363 ]

Paul Benedict commented on LANG-508:
------------------------------------

I am preparing to use java.lang.String#format over MessageFormat.

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12783387#action_12783387 ]

Mark Struberg commented on LANG-508:
------------------------------------

Thanks Paul!

Is there a repo where you can share your changes?
If you like to do the changes I'd be happy to provide the unit tests.
If there is anything I can do, then please let me know.
txs,
strub

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12783426#action_12783426 ]

Paul Benedict commented on LANG-508:
------------------------------------

Mark, thanks for the volunteering. The code is tentative, and the unit tests are failing because I am not really finished; hoping to get feedback before I bury myself in the testing process. :-) If you want to download and compile, please do -- the feedback will be highly appreciated.

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12841768#action_12841768 ]

Henri Yandell commented on LANG-508:
------------------------------------

Paul - you didn't attach any code or point to a repo.

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12890477#action_12890477 ]

Henri Yandell commented on LANG-508:
------------------------------------

I'm going to assume this was the commit that Paul made the day before his comment above:

------------------------------------------------------------------------
r885195 | pbenedict | 2009-11-28 22:30:23 -0800 (Sat, 28 Nov 2009) | 1 line

LANG-508: Allow exception message parameters as varargs, employ String#format to format exception message, full documentation update
------------------------------------------------------------------------

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Closed: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-508.
------------------------------

    Resolution: Fixed

Closing this out as afaict it's done.

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.