<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=kdonald" rel="nofollow">Keith Donald</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7839?redirect=false" rel="nofollow">SPR-7839</a></strong> and commented</p>
<p dir="auto">This is effecting the mvc-showcase sample after upgrading from 3.0.4 to 3.0.5.</p>
<p dir="auto">In the failing scenario, I'm attempting to bind to:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class JavaBean {

    private NestedBean nested;

}

public class NestedBean {

    private String foo;

    private List&lt;NestedBean&gt; list;
	
    private Map&lt;String, NestedBean&gt; map;

}"><pre class="notranslate"><code class="notranslate">public class JavaBean {

    private NestedBean nested;

}

public class NestedBean {

    private String foo;

    private List&lt;NestedBean&gt; list;
	
    private Map&lt;String, NestedBean&gt; map;

}
</code></pre></div>
<p dir="auto">(Note: getters and setters have been omitted for brevity)</p>
<p dir="auto">The actual binding expression is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="http://localhost:8080/mvc-showcase/convert/bean?nested.foo=bar&amp;nested.list[0].foo=baz&amp;nested.map[key].list[0].foo=bip"><pre class="notranslate"><code class="notranslate">http://localhost:8080/mvc-showcase/convert/bean?nested.foo=bar&amp;nested.list[0].foo=baz&amp;nested.map[key].list[0].foo=bip
</code></pre></div>
<p dir="auto">During binding, the "nested" property is initially null and the expectation is "auto-grow" behavior will kick-in.</p>
<p dir="auto">The stack trace of the runtime exception that is thrown is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="org.springframework.beans.NullValueInNestedPathException: Invalid property 'nested.map[key]' of bean class [org.springframework.samples.mvc.convert.JavaBean]: Could not determine property type for auto-growing a default value
	org.springframework.beans.BeanWrapperImpl.createDefaultPropertyValue(BeanWrapperImpl.java:601)
	org.springframework.beans.BeanWrapperImpl.setDefaultValue(BeanWrapperImpl.java:593)
	org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:558)
	org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:532)
	org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:533)
	org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:890)
	org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
	org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:673)
	org.springframework.validation.DataBinder.doBind(DataBinder.java:569)
	org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191)
	org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:110)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.doBind(AnnotationMethodHandlerAdapter.java:736)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:805)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:359)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.samples.mvc.flash.FlashMapFilter.doFilterInternal(FlashMapFilter.java:33)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
"><pre class="notranslate"><code class="notranslate">org.springframework.beans.NullValueInNestedPathException: Invalid property 'nested.map[key]' of bean class [org.springframework.samples.mvc.convert.JavaBean]: Could not determine property type for auto-growing a default value
	org.springframework.beans.BeanWrapperImpl.createDefaultPropertyValue(BeanWrapperImpl.java:601)
	org.springframework.beans.BeanWrapperImpl.setDefaultValue(BeanWrapperImpl.java:593)
	org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:558)
	org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:532)
	org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:533)
	org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:890)
	org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
	org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:673)
	org.springframework.validation.DataBinder.doBind(DataBinder.java:569)
	org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191)
	org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:110)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.doBind(AnnotationMethodHandlerAdapter.java:736)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:805)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:359)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.springframework.samples.mvc.flash.FlashMapFilter.doFilterInternal(FlashMapFilter.java:33)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

</code></pre></div>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398108524" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12370" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12370/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12370">#12370</a> Regression binding to nested properties on map values with auto-grow (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 3 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=bosmon" rel="nofollow">Antranig Basman</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2981?redirect=false" rel="nofollow">SPR-2981</a></strong>* and commented</p>
<p dir="auto">When making large numbers of instantiations, in particular at short scopes such as within an HTTP request, Spring core performance can become a bottleneck. Note that this appears to be an orthogonal problem to that referred to in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398072320" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7460" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7460/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7460">#7460</a> since this affects singleton and non-singleton beans alike, even (and, actually especially) in a single-threaded context. This is suggested also by the fact that this speed test is affected relatively little by the change from Spring 1.2.8 to 2.0.1 (slows by around 4%)</p>
<p dir="auto">There is a test project in our SVN tagged at <a href="https://saffron.caret.cam.ac.uk/svn/projects/TestRSAC/tags/J-ServletUtil-1.2" rel="nofollow">https://saffron.caret.cam.ac.uk/svn/projects/TestRSAC/tags/J-ServletUtil-1.2</a> which demonstrates the issue. A modest-sized container (30 beans with varying numbers of properties from 1 to 13) is fired up in various versions of Spring, and is subjected to repeated cycles of a fetch of the most derived bean followed by a call to destroySingletons(). This stabilises in the region of 8ms per instantiation of the bean set (for these 30 beans, on a fairly modest laptop). This would obviously be an unacceptable per-request overhead if occuring on each HTTP cycle.</p>
<p dir="auto">It's worth comparing this much lower figure with that of the 6-bean container in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398072320" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7460" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7460/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7460">#7460</a> - I think much of the difference lies in the considerably greater number of properties (some of which require conversion) on the beans in this test, which is more representative of a real-world container. For comparison purposes a run with a SINGLE leaf bean instantiates the container in only 22 microseconds, more than 400 times faster - demonstrating that the overhead is really a per-bean one, and strongly penalising beans with larger and more complex property sets.</p>
<p dir="auto">Profiling suggests that around 30% of the time is being lost in Sun introspection code, and a further 30% in instantiation of BeanWrapperImpl objects, which appear to be fabricated in a complete fresh set for every property set. Synchronisation also seems to be a significant part of the overhead. Even with removal of those first two two sources of overhead, the lag from this test instantation still couldn't be overwhelmingly expected to be &lt;1ms, which is still somewhat dubious.</p>
<p dir="auto">This is the main reason for development of "RSAC", a lightweight "Spring core" workalike, which sacrifices a good deal of Spring's flexibility (multi-threaded access, dynamic modifications to container heirarchy) in order to focus on the core cases of instantiations of and access to a set of beans bound to a single thread (typically within an HTTP request). Request-scope IoC has proved a big architectural benefit for the coherence and portability of RSF, and it would be marvellous if at some point we could stop maintaining RSAC and have similar capabilities within the Spring core :P - post 2.0 it now seems conceivable that this could become packaged as some new kind of Scope within Spring.</p>
<p dir="auto">General notes on RSAC at <a href="http://www2.caret.cam.ac.uk/rsfwiki/Wiki.jsp?page=RSAC" rel="nofollow">http://www2.caret.cam.ac.uk/rsfwiki/Wiki.jsp?page=RSAC</a> - the key points are that most of Spring core is implemented (with the notable exceptions of constructor injection and autowiring), and since it relies on genuine Spring core for reading BeanDefinitions it is immune to upgrades in the container file format. RSAC is generally around 50-80x faster at Spring proper at instantiating the TestRSAC context file. Raw numbers follow:</p>
<p dir="auto">Results (1.8Ghz Pentium M, SpeedStep engaged, JDK 1.4.2, Windows 2000)</p>
<p dir="auto">Main container (requestscope.xml, 30 beans)</p>
<p dir="auto">Spring 1.2.8:<br>
1000 instantations in 24695 ms: 24.695ms/instance<br>
10000 instantations in 239705 ms: 23.970ms/instance<br>
Spring 2.0.1:  1000 instantations in 25296 ms: 25.296ms/instance<br>
RSAC 1.2:<br>
1000 instantations in 631 ms: 0.631ms/instance<br>
10000 instantations in 4066 ms: 0.407ms/instance<br>
100000 instantations in 38085 ms: 0.381ms/instance</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(SpeedStep disengaged, maximum CPU)               "><pre class="notranslate"><code class="notranslate">(SpeedStep disengaged, maximum CPU)               
</code></pre></div>
<p dir="auto">Spring 1.2.8:  1000 instantations in 8232 ms: 8.232ms/instance<br>
RSAC 1.2:      10000 instantations in 1342 ms: 0.134ms/instance</p>
<p dir="auto">Tiny container (tinyrequestscope.xml, 1 bean, maximum CPU)</p>
<p dir="auto">Spring 1.2.8:  1000000 instantations in 21701 ms: 0.022ms/instance<br>
RSAC 1.2:      10000000 instantations in 16044 ms: 0.0016ms/instance</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398077580" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8109" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8109/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8109">#8109</a> Spring Bean Factory creation of Prototype (non-singleton) beans causes serious performance degradation under load (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398072320" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7460" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7460/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7460">#7460</a> Poor performance creating non-singleton beans with many threads</li>
</ul>
<p dir="auto">2 votes, 5 watchers</p>