[GitHub] [wicket] theigl opened a new pull request #454: WICKET-6833 Reduce allocations for PageParameters.mergeWith

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

[GitHub] [wicket] theigl opened a new pull request #454: WICKET-6833 Reduce allocations for PageParameters.mergeWith

GitBox

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


   This PR reduces allocations in `PageParameters.mergeWith`. As a side-effect, it increases throughput 4x.
   
   **Master**
   Benchmark    |                      Mode |  Cnt    |      Score     |      Units
   ------------ | ------------- |  ------------- |  --: | -------------
   ParameterBenchmarks.mergeWith                               |    thrpt  |  3 |  **1746723,436**  | ops/s
   ParameterBenchmarks.mergeWith:·gc.alloc.rate.norm           |    thrpt  |  3 |     1600,190  | B/op
   ParameterBenchmarks.mergeWith:·gc.churn.G1_Eden_Space.norm  |    thrpt  |  3 |     1602,183  | B/op
   
   **Branch**
   Benchmark    |                      Mode |  Cnt    |      Score     |      Units
   ------------ | ------------- |  ------------- |  --: | -------------
   ParameterBenchmarks.mergeWith                                |   thrpt |   3 | **7223753,855** |  ops/s
   ParameterBenchmarks.mergeWith:·gc.alloc.rate.norm            |   thrpt |   3 |     320,046 |  B/op
   ParameterBenchmarks.mergeWith:·gc.churn.G1_Eden_Space.norm   |   thrpt |   3 |     320,760 |  B/op
   
   https://issues.apache.org/jira/browse/WICKET-6833


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [wicket] martin-g commented on a change in pull request #454: WICKET-6833 Reduce allocations for PageParameters.mergeWith

GitBox

martin-g commented on a change in pull request #454:
URL: https://github.com/apache/wicket/pull/454#discussion_r495698598



##########
File path: wicket-request/src/main/java/org/apache/wicket/request/mapper/parameter/PageParameters.java
##########
@@ -294,35 +293,48 @@ public PageParameters add(final String name, final Object value, final int index
  Args.notEmpty(name, "name");
  Args.notNull(value, "value");
 
- if (namedParameters == null)
- {
- namedParameters = new ArrayList<>(1);
- }
-
- List<String> values = new ArrayList<>();
  if (value instanceof String[])
  {
- values.addAll(Arrays.asList((String[])value));
+ addNamed(name, (String[]) value, index, type);
  }
  else
  {
- values.add(value.toString());
+ addNamed(name, value.toString(), index, type);
+ }
+
+ return this;
+ }
+
+ private void addNamed(String name, String[] values, int index, Type type)
+ {
+ if (namedParameters == null)

Review comment:
       It would be better to add `&& values.length > 0`




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [wicket] theigl commented on a change in pull request #454: WICKET-6833 Reduce allocations for PageParameters.mergeWith

GitBox
In reply to this post by GitBox

theigl commented on a change in pull request #454:
URL: https://github.com/apache/wicket/pull/454#discussion_r495786864



##########
File path: wicket-request/src/main/java/org/apache/wicket/request/mapper/parameter/PageParameters.java
##########
@@ -294,35 +293,48 @@ public PageParameters add(final String name, final Object value, final int index
  Args.notEmpty(name, "name");
  Args.notNull(value, "value");
 
- if (namedParameters == null)
- {
- namedParameters = new ArrayList<>(1);
- }
-
- List<String> values = new ArrayList<>();
  if (value instanceof String[])
  {
- values.addAll(Arrays.asList((String[])value));
+ addNamed(name, (String[]) value, index, type);
  }
  else
  {
- values.add(value.toString());
+ addNamed(name, value.toString(), index, type);
+ }
+
+ return this;
+ }
+
+ private void addNamed(String name, String[] values, int index, Type type)
+ {
+ if (namedParameters == null)

Review comment:
       Done




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [wicket] theigl merged pull request #454: WICKET-6833 Reduce allocations for PageParameters.mergeWith

GitBox
In reply to this post by GitBox

theigl merged pull request #454:
URL: https://github.com/apache/wicket/pull/454


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[hidden email]