This is an automated email from the ASF dual-hosted git repository. papegaaij pushed a commit to branch wicket-6774 in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 44e5809d592858ab9c06f66cbecc2dffc9bef2bd Author: Emond Papegaaij <[email protected]> AuthorDate: Fri Sep 4 22:23:54 2026 +0200 WICKET-6774: check FLAG_MODEL_SET before unpacking the state Reading a model went through the type check on Component.data first and only then consulted the flag, so components without a model paid for the check before being told there was nothing to find. Most components have no model at all: of 548285 components measured on a production application, 61% have none. Testing the flag first skips the check for those entirely. The flag is authoritative, since it is set exactly when a model is stored, which is the same order master uses in getModelImpl(). Measured with wicket-benchmarks over an array holding every state shape at once, 2 forks, ns/op: readModelMixedShapes 21.28 -> 16.54 -22% which brings the total for this path to 30.17 -> 16.54, -45%, against 10.59 for master. The remainder is not explained by dispatch or by check order and would need perfasm to attribute; at roughly 0.6ns per model read it is small next to the gains on the other two accessors. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --- wicket-core/src/main/java/org/apache/wicket/ComponentState.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/ComponentState.java b/wicket-core/src/main/java/org/apache/wicket/ComponentState.java index d19e2a892f..737726926e 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ComponentState.java +++ b/wicket-core/src/main/java/org/apache/wicket/ComponentState.java @@ -154,11 +154,18 @@ final class ComponentState implements Serializable */ static IModel< ? > getModel(Object state, boolean modelSet) { + // the flag is authoritative: with no model set there is nothing to find, so the type + // check can be skipped entirely. Reading a model is far more common than reading the + // other two kinds of state, and most components have no model at all. + if (!modelSet) + { + return null; + } if (state instanceof ComponentState) { return ((ComponentState) state).getModel(); } - return modelSet ? (IModel< ? >) state : null; + return (IModel< ? >) state; } /**
