Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
9.12.0
-
None
Description
We noticed a very substantial amount of allocations coming from Component#internalRenderHead:
This is the relevant part of the code:
StringResponse markupHeaderResponse = new StringResponse(); Response oldResponse = getResponse(); RequestCycle.get().setResponse(markupHeaderResponse); try { // Make sure the markup source strategy contributes to the header first // to be backward compatible. WICKET-3761 getMarkupSourcingStrategy().renderHead(this, container); CharSequence headerContribution = markupHeaderResponse.getBuffer(); if (Strings.isEmpty(headerContribution) == false) { response.render(StringHeaderItem.forString(headerContribution)); } } finally { RequestCycle.get().setResponse(oldResponse); }
The code always allocates a new StringResponse for rendering potential markup header contributions. Internally, this creates a new AppendingStringBuffer with capacity 128.
In my application, we do not use <wicket:head> tags at all. So 99.9% of these allocations are completely unnecessary.
Ideally, I'd like to get rid of the temporary StringResponse, but I don't know if thats possible without breaking things.
Another solution would be to create a LazyStringResponse that initializes the internal String buffer on first use.