<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Performance Archives - Sourced Code</title>
	<atom:link href="https://sourcedcode.com/blog/category/aem/performance/feed" rel="self" type="application/rss+xml" />
	<link>https://sourcedcode.com</link>
	<description>AEM Blog Made Just for You.</description>
	<lastBuildDate>Thu, 14 Sep 2023 05:29:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.8</generator>

<image>
	<url>https://sourcedcode.com/wp-content/uploads/2019/09/cropped-favicon-32x32.png</url>
	<title>Performance Archives - Sourced Code</title>
	<link>https://sourcedcode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Optimizing &#038; Debugging Search Queries, Explain Query Tool AEM</title>
		<link>https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem</link>
					<comments>https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 09 Sep 2023 03:29:56 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6092</guid>

					<description><![CDATA[<p>The &#8220;Explain Query Tool&#8221; tool assists developers in understanding, optimizing, and debugging search queries, which are crucial for the AEM&#8217;s performance and accurate content delivery. Understanding the Explain Query Tool The Explain Query Tool essentially breaks down and explains the steps and processes a query goes through in AEM. Think of it as a &#8216;debug [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem">Optimizing &#038; Debugging Search Queries, Explain Query Tool AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The &#8220;Explain Query Tool&#8221; tool assists developers in understanding, optimizing, and debugging search queries, which are crucial for the AEM&#8217;s performance and accurate content delivery.</p>
<hr class="spacer-larger"/>
<h2>Understanding the Explain Query Tool</h2>
<p>The Explain Query Tool essentially breaks down and explains the steps and processes a query goes through in AEM. Think of it as a &#8216;debug mode&#8217; for your search queries. It provides insights into how the system interprets the query, the indexes it leverages, the estimated cost of the query, and other essential metrics.</p>
<hr class="spacer-larger"/>
<h2>Benefits of Using the Explain Query Tool:</h2>
<ul>
<li><strong>Performance Analysis</strong>: By revealing how the system interprets and executes the query, developers can identify bottlenecks or inefficiencies.</li>
<li><strong>Better Indexing</strong>: Developers can understand which indexes are being used and optimize or create new ones accordingly.</li>
<li><strong>Debugging</strong>: It becomes easier to pinpoint issues in complex queries when developers can visualize each step.</li>
</ul>
<hr class="spacer-larger"/>
<h2>Using Explain Query Tool with Different AEM Backend Search APIs</h2>
<h3>1. SQL2:</h3>
<p>SQL2 is the SQL-like query language used in AEM, and it&#8217;s one of the primary ways developers retrieve data from the JCR (Java Content Repository).</p>
<h4>How to Use:</h4>
<p>Navigate to the AEM Query Performance Tool, and select on the &#8220;Explain Query&#8221; tab. Choose the &#8220;Language&#8221; drop down to be SQL-JCR2, and input the JCR-SQL2 query that you are trying to test. Now click on explain, and you&#8217;ll see a breakdown of the query&#8217;s interpretation and execution.</p>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-large"/>
<h3>2. Query Builder API:</h3>
<p>Query Builder API allows developers to build search queries programmatically using a more intuitive map-based syntax. It abstracts some complexities of the JCR, offering a more accessible way to retrieve content.</p>
<h4>How to Use:</h4>
<p>Navigate to the AEM Query Performance Tool, and select on the &#8220;Explain Query&#8221; tab. Choose the &#8220;Language&#8221; drop down to be Query Builder, and input your Query Builder query that you are trying to test. Now click on explain, and you&#8217;ll see a breakdown of the query&#8217;s interpretation and execution.</p>
<div class="mention-block--gold">
<strong>Note</strong><br />
For Query Builder queries, only the generated XPath is included in the explanation and result counts. For an in-depth analysis (including filtering and facets extraction), use the <a href="http://localhost:4502/libs/cq/search/content/querydebug.html" rel="noopener" target="_blank">Query Builder Debugger tool</a>.
</div>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-large"/>
<h3>3. XPath:</h3>
<p>XPath is another way of querying the JCR in AEM. While it&#8217;s less commonly used than SQL2, it can be more expressive and powerful for certain hierarchical data structures.</p>
<h4>How to Use:</h4>
<p>Navigate to the AEM Query Performance Tool, and select on the &#8220;Explain Query&#8221; tab. Choose the &#8220;Language&#8221; drop down to be XPath, and input the XPath Query that you are trying to test. Now click on explain, and you&#8217;ll see a breakdown of the query&#8217;s interpretation and execution.</p>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-larger"/>
<h2>Other Options for the AEM Query Performance Tool</h2>
<ol>
<li><strong>Include Execution Time</strong>: Execution time will be reported after running the query. Please note that long running queries will report an explanation with a delay.</li>
<li><strong>Read first page of results</strong>: The first 20 results will be read after running the query.  Please note that long running queries will report an explanation with a delay, and the overall execution will timeout after 60 seconds.</li>
<li><strong>Include Node Count</strong>: The node count is calculated by iterating the full result set of the query. Please note that long running queries will report an explanation with a delay, and the overall execution will timeout after 60 seconds.</li>
</ol>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-larger"/>
<h2>Conclusion</h2>
<p>The Explain Query Tool in AEM is a powerful ally for developers, especially those heavily invested in ensuring the performance and accuracy of their search queries. By familiarizing oneself with this tool across the various backend search APIs, developers can optimize their AEM platform for both performance and maintainability, ensuring that the content delivery is swift and relevant.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem">Optimizing &#038; Debugging Search Queries, Explain Query Tool AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sling Model Field Injection vs Constructor Injection Memory Consumption</title>
		<link>https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 23 Apr 2020 15:47:02 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1361</guid>

					<description><![CDATA[<p>Article was last updated on June 7th, 2020. Sling Models field injectors are used to support injection of AEM Library-specific context objects. For example, @ScriptVariable SightlyWCMMode will inject the WCMMode object, @ScriptVariable Resource will inject the current resource object, and @ScriptVariable Style will inject the Style object. These objects are typically stored within the object, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption">AEM Sling Model Field Injection vs Constructor Injection Memory Consumption</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<hr/>
<div class="mention-block" align="center">Article was last updated on June 7th, 2020.</div>
<hr/>
<p>Sling Models field injectors are used to support injection of AEM Library-specific context objects. For example, @ScriptVariable SightlyWCMMode will inject the WCMMode object, <span class="code-highlight-primary">@ScriptVariable Resource</span> will inject the current resource object, and <span class="code-highlight-primary">@ScriptVariable Style</span> will inject the Style object. These objects are typically stored within the object, so it can be later used to construct the Sling Model&#8217;s properties to make available to the context who&#8217;s calling it. </p>
<p>With the Apache Sling Model&#8217;s injector specific annotations, we are able to inject Sling Objects, AEM Services, OSGI Components, etc&#8230; directly into the context of the Sling Model easily without much hassle. </p>
<div class="mention-block"><strong>What is the catch?</strong> Whenever we are injecting objects into our Sling Models via field injection for later use, an instantiated Sling Model adaptable stores a reference of those object in memory; stored injected objects in the Sling Model instance will consume memory.</div>
<p>The Sling Model constructor injection is also supported (as of Sling Models 1.1.0), and its documented that it does not store the reference to the adaptable, lets test this out.</p>
<p><strong>In this article, we will test the Sling Model memory consumption with two scenarios:</strong></p>
<ol>
<li><a href="#test-annotation-specific">Test 1: Sling Model Field Injection</a></li>
<li><a href="#test-constructor-injection">Test 2: Sling Model Constructor Injection</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
<hr class="spacer-large"/>
<h2 id="test-annotation-specific">Test 1: Sling Model Field Injectors</h2>
<p>I have 3 injected AEM objects to be stored in my class variables into my Sling Model via field injection; another 3 variables used to expose data to the calling context. Each AEM objects will then be used in the @PostConstruct method, where data would be extracted from each object, and set in the class variables for exposure to the calling context.</p>
<p>I then ran a test for getting the bytes in size for a specific object using the Lucene&#8217;s until RamUsageEstimator. </p>
<p><strong style="color:red;">The memory byte size of the Sling Model adaptable object is 40</strong>.</p>
<p><strong>MyModel.class : RamUsageEstimator Results:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.util.RamUsageEstimator</span><span style="color: #339933;">;</span><br />
...<br />
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyModel.class + shallowSizeOf:&quot;</span> <span style="color: #339933;">+</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">lucene</span>.<span style="color: #006633;">util</span>.<span style="color: #006633;">RamUsageEstimator</span>.<span style="color: #006633;">shallowSizeOf</span><span style="color: #009900;">&#40;</span>req.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>MyModel.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>MyModel.class:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource resource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest slingHttpServletRequest<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentResourcePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentPagePagePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> requestParam<span style="color: #339933;">;</span><br />
<br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> initModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentResourcePath <span style="color: #339933;">=</span> resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentPagePagePath <span style="color: #339933;">=</span> currentPage.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; requestParam <span style="color: #339933;">=</span> slingHttpServletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myParam&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="test-constructor-injection">Test 2: Sling Model Constructor Injection</h2>
<p>I have 3 injected AEM objects via Constructor Injection; another 3 variables used to expose data to the calling context. This time, I am not storing the AEM objects in as class variables. We can definitely see a change in byes size here.</p>
<p><strong style="color:green;">The memory byte size of the Sling Model adaptable object is 24</strong>.</p>
<p><strong>MyModelConstructor.class : RamUsageEstimator Results:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.util.RamUsageEstimator</span><span style="color: #339933;">;</span><br />
...<br />
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyModelConstructor.class + shallowSizeOf:&quot;</span> <span style="color: #339933;">+</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">lucene</span>.<span style="color: #006633;">util</span>.<span style="color: #006633;">RamUsageEstimator</span>.<span style="color: #006633;">shallowSizeOf</span><span style="color: #009900;">&#40;</span>req.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>MyModelConstructor.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>MyModelConstructor.class:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyModelConstructor <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentResourcePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentPagePagePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> requestParam<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> MyModelConstructor<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentPage&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource resource,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slingHttpServletRequest&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletRequest slingHttpServletRequest<br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentResourcePath <span style="color: #339933;">=</span> resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentPagePagePath <span style="color: #339933;">=</span> currentPage.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; requestParam <span style="color: #339933;">=</span> slingHttpServletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myParam&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h2 id="conclusion">Conclusion</h2>
<p>An AEM object that has been field injected into a variable that is only being minimally used holds onto memory which will/can be be wasting resources. If AEM objects are not needed, then the Constructor Injection method can be appropriately used.</p>
<p>It&#8217;s not rocket science. We see the results! Test 2 has less instance variables than Test 1; of course Test 2 will have a smaller Object (in byte size) than Test 1.</p>
<p>My only recommendation is this. When you are using AEM Objects, ask yourself, how is this Object being used?</p>
<p>This article highlights why Sling Model Constructor Injection via constructor is useful in our AEM development.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption">AEM Sling Model Field Injection vs Constructor Injection Memory Consumption</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Improve Performance of AEM Components During Development Phase</title>
		<link>https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase</link>
					<comments>https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 06 Nov 2019 19:50:22 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Performance]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=965</guid>

					<description><![CDATA[<p>Web performance is how quick web pages are successfully downloaded and viewable on the visitor&#8217;s browser. When we say &#8220;Web Performance Optimization&#8221;, this means that we are optimising or increasing web performance. Quicker download speeds of websites, in general, have shown in user contentment, retention, and loyalty. Especially with AEM enterprise websites, our motive is [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase">Improve Performance of AEM Components During Development Phase</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Web performance is how quick web pages are successfully downloaded and viewable on the visitor&#8217;s browser. When we say &#8220;Web Performance Optimization&#8221;, this means that we are optimising or increasing web performance. Quicker download speeds of websites, in general, have shown in user contentment, retention, and loyalty.</p>
<p>Especially with AEM enterprise websites, our motive is to deliver high-performance websites. Us as developers, we try our best to keep the code our clean and optimum. When it comes to creating new AEM components, instead of waiting for the batch of approved non-released code to be deployed into a performance testing environment, you can monitor the performance of your AEM components beforehand in local author.</p>
<p>Quickly view and monitor the performance of your component&#8217;s Sightly front-end logic and Sling Models back-end logic has never been so easy!</p>
<div class="mention-block">
During the development of AEM page/content components, since AEM 6.2, the platform has provided a tool for us, developers, to conveniently monitor the server-side computational time. This tool is called the <strong>Developer Mode</strong>. This allows you to find a slow loading page/content components, so you can take action and optimize it to the optimal! In this article, you will learn how to understand, and then improve, the page loading speed by identifying slow components by monitoring component&#8217;s server-side computational time.</div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2019/11/computational-time.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/computational-time.jpg" alt="" width="60%"/></a></p>
<h3>How to Review Server-Side Computational Time with &#8220;Developer Mode&#8221;</h3>
<p><strong>&#8220;Develop Mode&#8221; lives in authoring AEM environment, inside of the editable page.</strong></p>
<ol>
<li style="list-style-type: none;">
<ol>
<li>Visit any page that you would like to measure. Ensure the targeted component sits on the page, and if not, add the component to the editable page. <a href="http://localhost:4502/editor.html/content/we-retail/language-masters/en.html" target="_blank" rel="noopener noreferrer">http://localhost:4502/editor.html/content/we-retail/language-masters/en.html</a></li>
<li>Click on the tool-bar drop-down selector, and select on <strong>&#8220;Develop&#8221;</strong>.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-drop-down-menu.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-drop-down-menu.png" alt="" width="50%" /></a></li>
<li>The page is reviewed with a side-panel which includes the component tree; the component tree is populated structure of all the components that live within the targeted page. Immediately you can see the server-side computational time. This information is extremely useful when you are trying to optimize your AEM website. The metric used here is <strong>ms</strong> for milliseconds and <strong>s</strong> for seconds. As you can see in the image provided below, Page .033s indicates that the entire page takes 1/3 of a second to load all the components.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools.png" alt="" width="50%" /></a></p>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="6046636040"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
</li>
<li>Along with a grouped server-side computational time, Individual components computational time will also be displayed. In the screenshot below, we are taking a look at the performance of the header component.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-header-view-details-edit-script.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-header-view-details-edit-script.png" alt="" width="50%" /></a>
</li>
<li><strong>Hooray!</strong> You Have Completed this Tutorial. As an extension to this tutorial, we will learn about the &#8220;view details&#8221;, &#8220;edit script&#8221;, and also the &#8220;errors&#8221; option.<br /><a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools-1.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools-1-1024x659.png" alt="" width="50%" /></a><br />
<strong>Buttons Legend</strong>:<br />
<strong>View Details</strong>: a link to a list that shows all the component scripts used to render the component, and also the repository content path for this specific component.<br />
<strong>Edit Script</strong>: a link that opens the component&#8217;s script in CRXDE Lite.<br />
<strong>Component Details</strong>: a link that takes you to the component details page.</li>
</ol>
</li>
</ol>
<div class="mention-block"><b>Last Thoughts</b><br />
This tool is definitely useful for when you are trying to optimize your AEM website, looking at the underlying cause of your slow rendered AEM page. Now go and optimize your logic to reduce page loading time!</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase">Improve Performance of AEM Components During Development Phase</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
