[KULRICE-10353] Inline processing of FreeMarker templates Created: 02/Sep/13  Updated: 21/Apr/14  Resolved: 14/Sep/13

Status: Closed
Project: Kuali Rice Development
Component/s: Development, User Experience (UX)
Affects Version/s: None
Fix Version/s: 2.3.1
Security Level: Public (Public: Anyone can view)

Type: Improvement Priority: Major
Reporter: Mark Fyffe (Inactive) Assignee: Mark Fyffe (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0 minutes
Time Spent: 2 days
Original Estimate: 1 day, 6 hours

Attachments: Text File kulrice-10353-script_template_inline.patch    
Issue Links:
fixes KULRICE-10423 Freemarker Exception on Login page Closed
relates to KULRICE-9794 Reduce template invocations Open
relates to KULRICE-9423 Research string template method for g... In Progress
is related to KULRICE-9774 Review template logic Open
Similar issues:
KULRICE-12658MultiFileUpload freemarker templates for component and row templates
KULRICE-10436Demo LIbrary, Layout Managers, CssGridLayout and many others, inline Freemarker Exception
KULRICE-11140AFT Failure KRAD Demo Labs KSA Transaction inline Freemarker Exception
KULRICE-11536AFT Failure Rice Sampleapp Krad Configuration clicking all day checkbox inline Freemarker exception
KULRICE-8710Template Browser Mob tests with freemarker
KULRICE-10340KRAD Demo Library Account Multi-Value Lookup inline Freemarker exception searching when result checked.
KULRICE-10421AFT Failure: DemoLibraryCollectionFeaturesLightTableSmokeTest inline freemarker exception
KULRICE-11869FreeMarker error in testTransactionView
KULRICE-7901JSP templates replaced with Freemarker
KULRICE-10532KRAD Demo Library Freemarker Exception in header.ftl
Epic Link: Performance
Rice Module:
Sprint: 2.3.1 Sprint 2
KAI Review Status: Not Required
KTI Review Status: Not Required
Code Review Status: Not Required
Include in Release Notes?:


Based on analysis recorded in KULRICE-10260, FreeMarker rendering of complex views is in part impacted by excessive BeansWrapper method invocation centered around high-traffic macros such as script and template.

To reduce this introspection overhead and improve overall performance of view rendering at the FreeMarker phase, provide a mechanism for passing FreeMarker rendering control to inline Java code then convert targeted macros to use this inline mechanism instead of handling expensive internal rendering logic through the exclusive use of .ftl template code.

Initial targeted Macros are script.ftl and template.ftl. Once these have been converted, an additional pass at analysis and identification of targeted macros using Performance Medium should lead to further opportunities to improve performance.

Original estimate:

  • 4h - Implementation of FreeMarker extensions to support inline processing.
  • 3h - Conversion of script and template to inline.
  • 4h - Repeat analysis and identification of additional targeted macros.
  • 2h - Conversion of additional macros to inline.
  • 2h - Code clean up and prep for release.


Comment by Mark Fyffe (Inactive) [ 02/Sep/13 ]

Committed inline processing extensions to kuali-freemarker

Comment by Mark Fyffe (Inactive) [ 02/Sep/13 ]

Attached patch for conversion of script.ftl and template.ftl to inline processing.

Comment by Mark Fyffe (Inactive) [ 03/Sep/13 ]

Converted collectionGroup and stacked templates to inline processing based on repeat analysis.

After removing internal profiling, I'm now observing local Performance Medium runs as fast as 2.5s total request time - FreeMarker rendering time observed locally is down to 500ms-800ms.

2013-09-03 08:02:09,285 [http-8080-2] u:/d: INFO  org.kuali.rice.krad.uif.util.P
rocessLogger - KRAD Process Trace (request): Servlet Request /kr-krad/labs
  at org.kuali.rice.krad.uif.util.ProcessLoggingFilter.doFilter(ProcessLoggingFi
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicatio
Initial Memory Usage: 399.912M/935.750M/935.750M - 42% free
pre-handle..............................00:00.000 00:00.000 399.912M 0
build-view:Lab-PerformanceMedium........00:00.125 00:00.125 344.940M -54.970M
build-view-params:Lab-PerformanceMedium.00:00.000 00:00.125 344.940M 0
build-view-backup-params:Lab-Performance00:00.000 00:00.125 344.940M 0
perform-lifecycle:Lab-PerformanceMedium.00:00.000 00:00.125 344.940M 0
apply-model:Lab-PerformanceMedium.......00:00.063 00:00.188 475.445M 130.504M
apply-comp-model:Lab-PerformanceMedium..00:00.000 00:00.188 475.445M 0
apply-model-end:Lab-PerformanceMedium...00:01.031 00:01.219 232.450M -242.995M
perform-lifecycle-after-model:Lab-Perfor00:00.000 00:01.219 232.450M 0
perform-lifecycle-model-reindex:Lab-Perf00:00.000 00:01.219 228.941M -3.508M
perform-lifecycle-finalize:Lab-Performan00:00.687 00:01.906 232.375M 3.434M
perform-lifecycle-final-reindex:Lab-Perf00:00.016 00:01.922 228.809M -3.566M
perform-lifecycle-final:Lab-PerformanceM00:00.000 00:01.922 228.809M 0
validate-view:Lab-PerformanceMedium.....00:00.000 00:01.922 228.809M 0
post-handle.............................00:00.000 00:01.922 228.809M 0
after-completion........................00:00.672 00:02.594 238.001M 9.192M
after-completion-end....................00:00.031 00:02.625 237.676M -333.460k
Processing Complete.....................00:00.000 00:02.625 237.676M 0
  bean-property-read: 18090 (00:00.000/00:00.016/00:00.000)
    longest : KradLabsForm:mediumCollection2[1].subList[0]
  bean-property-write: 29665 (00:00.000/00:00.016/00:00.000)
    longest : Disclosure:bindingInfo.bindToForm
Elapsed Time: 00:02.625
Memory Usage: 237.676M/868.062M/910.250M - 27% free
Memory Delta: -162.234M/868.062M/910.250M - -18% free - tot delta: -67.687M

Will work next weekend to clean up and commit this effort.


Comment by Mark Fyffe (Inactive) [ 07/Sep/13 ]

Modified freemarker extensions related to this issue:

  • Changed #krad_inline directive to #inline
  • Changed names of FM extension classes:
    • InlineKradElement -> InlineTemplateElement
    • InlineKradAdaptor -> InlineTemplateAdaptor
    • KualiTemplateUtils -> InlineTemplateUtils

Added this change locally as 2.3.20-patch2, and modified local Rice 2.4 working copy to use updated names for directives and inline utilities. I'll be working this evening and tomorrow to clean up the a final version of krad-web-framework and krad-web for commit.


Comment by Mark Fyffe (Inactive) [ 14/Sep/13 ]

Updated rice pom.xml to point at freemarker-2.3.20-patch2

Converted groupWrap.ftl to inline to reduce duplication between inline and interpreted templates.

This issue should now be resolved.

Comment by Mark Fyffe (Inactive) [ 14/Sep/13 ]

Code review for inline template processing code changes:


Generated at Tue Jul 07 19:36:55 CDT 2020 using JIRA 6.1.5#6160-sha1:a61a0fc278117a0da0ec9b89167b8f29b6afdab2.