You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2017/09/12 16:08:23 UTC
[GitHub] brooklyn-server pull request #817: Optimizations
GitHub user ahgittin opened a pull request:
https://github.com/apache/brooklyn-server/pull/817
Optimizations
Minor things I noticed which were chewing up CPU and could be easily fixed
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/brooklyn-server optimize1
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-server/pull/817.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 #817
----
commit 330f89ee34ee450f00eb6760721d87d5a5466b25
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2017-09-11T10:03:52Z
more performance monitoring util routines
commit 14f0398dd500768aa00c4a003be24174448ebc7e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2017-09-11T14:43:18Z
optimization: skip conversion to then from TypeToken if we have a raw class as a type
this was a noticeable expense when doing profiling
commit aee1b610b6827dce89b5c4e0423b1c16a4d0c3b8
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2017-09-11T22:14:59Z
optimization: cache common type tokens
----
---
[GitHub] brooklyn-server pull request #817: Optimizations
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/817#discussion_r138591570
--- Diff: utils/common/src/main/java/org/apache/brooklyn/util/guava/TypeTokens.java ---
@@ -68,5 +85,19 @@
public static <T> Class<T> getRawRawType(TypeToken<T> token) {
return (Class)token.getRawType();
}
+
+ /** Checks that if both type and token are supplied, either exactly one is null, or
+ * they both refer to the same non-null type */
+ public static <T> void checkCompatibleOneNonNull(Class<? super T> type, TypeToken<T> typeToken) {
+ if ((type==null && typeToken!=null) || (type!=null && typeToken==null)) {
+ return;
+ }
+ if (type==null && typeToken==null) {
+ throw new NullPointerException("Type not set (neither class or type token)");
+ }
+ if (!type.equals(typeToken.getRawType())) {
+ throw new NullPointerException("Invalid types, token is "+typeToken+" (raw "+typeToken.getRawType()+") but class is "+type);
--- End diff --
This should be `IllegalArgumentException` or `IllegalStateException`, rather than NPE.
---
[GitHub] brooklyn-server issue #817: Optimizations
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the issue:
https://github.com/apache/brooklyn-server/pull/817
good comments @aledsage - thx - will apply both and merge
---
[GitHub] brooklyn-server pull request #817: Optimizations
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/brooklyn-server/pull/817
---
[GitHub] brooklyn-server pull request #817: Optimizations
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/817#discussion_r138592431
--- Diff: utils/common/src/main/java/org/apache/brooklyn/util/guava/TypeTokens.java ---
@@ -24,6 +24,14 @@
public class TypeTokens {
+ // creating TypeToken is surprisingly expensive so cache these common ones
+ public static TypeToken<String> STRING = TypeToken.of(String.class);
--- End diff --
If leaving as-is, then these should be `final`.
I'd have gone for:
```
public static final Map<Class<?>, TypeToken<?>> COMMON_TYPE_TOKENS = ImmutableMap.<Class<?>, TypeToken<?>>builder()
.put(String.class, TypeToken.of(String.class))
...
.build();
```
And:
```
TypeToken<?> result = COMMON_TYPE_TOKENS.get(raw);
if (result == null) result = TypeToken.of((Class<T>)raw);
return (TypeToken<T>) result;
```
---