You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Radu Cotescu (JIRA)" <ji...@apache.org> on 2018/08/29 14:53:00 UTC

[jira] [Commented] (SLING-7207) Get rid of runtime reflection in HTL expression evaluation

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

Radu Cotescu commented on SLING-7207:
-------------------------------------

In order to figure out the potential improvement of getting rid of reflection from property resolution I implemented support for compile time type resolution for first level property access. Therefore the following trivial script:
{code}
<div data-sly-use.ss="org.apache.sling.settings.SlingSettingsService">
 ${ss.slingId}
</div>
 {code}
was compiled into:
{code:java}
org.apache.sling.settings.SlingSettingsService _global_ss = null;
_global_ss = (org.apache.sling.settings.SlingSettingsService) renderContext.call("use", org.apache.sling.settings.SlingSettingsService.class.getName(), obj());
out.write("<div>");
{
    String var_0 = (("\n    " + renderContext.getObjectModel().toString(renderContext.call("xss", _global_ss.getSlingId(), "text"))) + "\n");
    out.write(renderContext.getObjectModel().toString(var_0));
}
out.write("</div>");
{code}
instead of:
{code:java}
Object _global_ss = null;
_global_ss = renderContext.call("use", org.apache.sling.settings.SlingSettingsService.class.getName(), obj());
out.write("<div>");
{
    String var_0 = (("\n    " + renderContext.getObjectModel().toString(renderContext.call("xss", renderContext.getObjectModel().resolveProperty(_global_ss, "slingId"), "text"))) + "\n");
    out.write(renderContext.getObjectModel().toString(var_0));
}
out.write("</div>");
{code}

Executing the two variants of the compiled script didn't show any significant performance gain, both scripts executing in around 2.4ms on my machine (MacBook Pro, Mid 2015, 2.5 GHz Intel Core i7). The behaviour was similar even after increasing the number of calls to {{$\{ss.slingId\}}} to 10 or more. I'd therefore conclude that the effort to resolve types at compile time is not really worth it.

> Get rid of runtime reflection in HTL expression evaluation
> ----------------------------------------------------------
>
>                 Key: SLING-7207
>                 URL: https://issues.apache.org/jira/browse/SLING-7207
>             Project: Sling
>          Issue Type: Improvement
>          Components: Scripting
>    Affects Versions: Scripting HTL Engine 1.0.20, Scripting HTL Compiler 1.0.0, Scripting HTL Java Compiler 1.0.0
>            Reporter: Vlad Bailescu
>            Assignee: Radu Cotescu
>            Priority: Major
>
> At the moment the following expression
> {code}
> <sly data-sly-use.obj="com.my.Obj">${obj.message}</sly>
> {code}
> generates this Java code:
> {code}
> Object _global_obj = null;
> _global_obj = renderContext.call("use", "com.my.Obj", obj());
> {
>     Object var_0 = renderContext.call("xss", renderContext.getObjectModel().resolveProperty(_global_obj, "message"), "text");
>     out.write(renderContext.getObjectModel().toString(var_0));
> }
> {code}
> Resolving the property is done via reflection at runtime. Given the fact that for most use providers (JS is an exception) we know the type of {{_global_obj}} we could determine the right method to call at compile time. Resulting code might look something like:
> {code}
> com.my.Obj _global_obj = renderContext.call("use", com.my.Obj.class, obj());
> {
>     Object var_0 = renderContext.call("xss", _global_obj.getMessage()), "text");
>     out.write(renderContext.getObjectModel().toString(var_0));
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)