[ 
https://issues.apache.org/jira/browse/WICKET-6774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18111648#comment-18111648
 ] 

ASF GitHub Bot commented on WICKET-6774:
----------------------------------------

papegaaij commented on code in PR #424:
URL: https://github.com/apache/wicket/pull/424#discussion_r3936391723


##########
wicket-core/src/main/java/org/apache/wicket/ComponentState.java:
##########
@@ -0,0 +1,1081 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.wicket.behavior.Behavior;
+import org.apache.wicket.behavior.InvalidBehaviorIdException;
+import org.apache.wicket.model.IModel;
+
+/**
+ * This class keeps track of the flexible state of a component: model, 
behaviors and meta data.
+ * These types of state vary per component. Not every component contains these 
elements or their
+ * numbers differ. The state is stored in the {@code data} field in {@link 
Component}. To keep the
+ * size of this state as small as possible, the following cases are identified:
+ * <ul>
+ * <li>No state at all: {@code data} is {@code null}
+ * <li>Only a model: {@code data} contains the model
+ * <li>Only one or more behaviors: {@code data} contains the behavior, or an 
array of behaviors
+ * <li>Only one or more meta data entries: {@code data} contains the entry, or 
an array of entries
+ * <li>A model and one or more behaviors: {@code data} contains an instance of
+ * {@link ModelBehaviorsComponentState}
+ * <li>A model and one or more meta data entries: {@code data} contains an 
instance of
+ * {@link ModelMetaDataComponentState}
+ * <li>One or more behaviors and one or more meta data entries: {@code data} 
contains an instance of
+ * {@link BehaviorsMetaDataComponentState}
+ * <li>A model, one or more behaviors and one or more meta data entries: 
{@code data} contains an
+ * instance of {@link ModelBehaviorsMetaDataComponentState}
+ * </ul>
+ * 
+ * @author papegaaij
+ */
+abstract class ComponentState implements Serializable

Review Comment:
   I think I tried interfaces earlier on in this branch, but they were slow. 
This code lives on very performance critical paths. Every ns makes a 
difference. I'll resurrect the branch. It was a fun experiment. I'd rather not 
put this in 10 as it might have some unforeseen side effects.





> Separate model, behaviors and metadata into separate fields
> -----------------------------------------------------------
>
>                 Key: WICKET-6774
>                 URL: https://issues.apache.org/jira/browse/WICKET-6774
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-core
>    Affects Versions: 9.0.0-M5
>            Reporter: Thomas Heigl
>            Priority: Minor
>         Attachments: ComponentBenchmarks.java, ComponentBenchmarks.java, 
> benchmarks.png
>
>
> While investigating performance issues with metadata in WICKET-6771, I 
> discovered that significant performance gains can be achieved by separating 
> models, behaviors, and metadata into separate fields.
> Currently, all three types of data are stored in a single, untyped field 
> {{Component.data}}. The idea is to minimize memory overhead by creating as 
> few objects as possible.
> If a model or a single behavior or metadata is added, {{data}} stores only a 
> reference to the object. When additional data is added, the reference becomes 
> an array.
> This is the most memory-efficient way to store these three types of data. But 
> it comes with a cost: code to manipulate that data structure is complex and 
> not as efficient because it has to take all possible combinations of data 
> into account.
> I suggest introducing 3 separate fields for the 3 types of data, trading a 
> little bit of memory for reduced complexity and performance gains.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to