You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by da...@apache.org on 2015/09/21 13:58:24 UTC

[3/8] wicket git commit: Documented the children field and map threshold

Documented the children field and map threshold


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7be920d4
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7be920d4
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7be920d4

Branch: refs/heads/master
Commit: 7be920d4403d719e26d2a131454928c086a7317c
Parents: 26cecdc
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Mon Sep 21 13:01:41 2015 +0200
Committer: Martijn Dashorst <ma...@gmail.com>
Committed: Mon Sep 21 13:01:41 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/MarkupContainer.java    | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/7be920d4/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
index c25c3db..4571c29 100644
--- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
@@ -100,13 +100,26 @@ public abstract class MarkupContainer extends Component implements Iterable<Comp
 	private static final long serialVersionUID = 1L;
 	
 	private static final int INITIAL_CHILD_LIST_CAPACITY = 12;
-	
+
+	/**
+	 * The threshold where we start using a Map to store children in, replacing a List. Adding
+	 * components to a list is O(n), and to a map O(1). The magic number is 24, due to a Map using
+	 * more memory to store its elements and below 24 children there's no discernible difference
+	 * between adding to a Map or a List.
+	 * 
+	 * We have focused on adding elements to a list, instead of indexed lookups because adding is an
+	 * action that is performed very often, and lookups often are done by component IDs, not index.
+	 */
 	private static final int MAPIFY_THRESHOLD = 24; // 32 * 0.75
 
 	/** Log for reporting. */
 	private static final Logger log = LoggerFactory.getLogger(MarkupContainer.class);
 
-	/** List of children or single child */
+	/**
+	 * The children of this markup container, if any. Can be a Component when there's only one
+	 * child, a List when the number of children is fewer than {@link #MAPIFY_THRESHOLD} or a Map
+	 * when there are more children.
+	 */
 	private Object children;
 
 	/**