Memory and String optimizations
I plan to do some refactorings on String/StringBuffer/StringBuilder usage.
I hope to lower memory usage for temporal object creation (the objects created within a single request) / GC overhead and maybe increase performance.
StringBuffer(thread safe) ->
StringBuilder(faster, not thread safe) where possible
- Set/optimize initial capacity for
StringBuilderwhere possible preventing string arrays to be recreated/copied in the buffer/builder internally
String.intern()if a string is likely to be used repeatedly
- Replace String concatenations over multiple statements into
- Review our
Encoders.encodeTemplateIdmethod which gets invoked hundreds of times within a single request, performing MD5-hashing each time.
Using the benchmark script developed by Chris Gersen, I will perform some tests on 2 pages using a local yellowgrass instance.
CPU scheduler was set to performance, not switching CPU speeds.
CONTINUE_PATH="$(basename $1 .cfg).continue"
find ./tests/*.war 2>/dev/null
find ./tests/*.sql.gz 2>/dev/null
SESSIONSQL="SELECT id FROM _SessionManager LIMIT 1;"
Avg Heap/req (MB) Avg req time (ms) 80% req times < (ms) issue page 32.53 98 98 project page 9.43 11 12
note: The system was not restarted, which renders this result kinda useless wrt request time measurements (may relate to OS caches)
Avg Heap/req (MB) Avg req time (ms) 80% req times < (ms) issue page 32.55 99 100 project page 9.43 12 12
Refactoring 2: Set initialize capacity for
With system restarted:
Avg Heap/req (MB) Avg req time (ms) 80% req times < (ms) issue page 32.24 97 98 project page 9.27 11 12
Illustrative result, without system restart:
Submitted by Elmer van Chastelet on 14 May 2013 at 08:53
Avg Heap/req (MB) Avg req time (ms) 80% req times < (ms) issue page 32.24 101 102 project page 9.29 12 12