Skip to content

Performance Issue with @ModelAttribute [SPR-15198] #19762

Closed

Description

@spring-projects-issues

Jochen Pier opened SPR-15198 and commented

There is a possible performance problem:

If you use:

@ModelAttribute
public void before(@ModelAttribute(name="test") TestClass test) {
	test.setPayload("myPayload");
}

it is MUCH (10x) slower than the same

@ModelAttribute
public void before(Model model) {
	TestClass t = new TestClass();
	t.setPayload("myPayload");
	model.addAttribute("test", t);
}

This is true especially in high traffic situations and is constantly getting worse (slower) over the time.

I think, maybe a hint in the documentation will be a good idea. (Or maybe you can find the problem)

Do you need a test-project?


Affects: 4.3.5

Issue Links:

Activity

  1. spring-projects-issues commented on Jan 27, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    ModelAttribute performs data binding so yes the details of the Object (how many fields, how many nested Objects, etc) could make a difference. In the very lease providing a TestClass object that approximates the real one would help. Or test project even better.

  2. spring-projects-issues commented on Jan 29, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Jochen Pier commented

    I just added a test-project to the repo.
    Please note: The problem seems to exists only in spring boot 1.4.3 - and NOT any more in spring boot 1.4.4!!
    (I just discovered this while testing) But perhaps it's worth checking anyway.

    Thank you!!

  3. spring-projects-issues commented on Feb 9, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    After taking a closer look, thanks for the sample, it appears the issue is a duplicate of #19626. The hotspot (~65% of time) is exactly in the same place as the first screenshot attached to #19626 but invoked from the ModelAttributeMethodProcessor. There is also a comment at the bottom about a similar report with an @ModelAttribute method. The versions also match (fixed in 4.3.6 which is what Spring Boot 1.4.4 is based on).

  4. added
    type: enhancement
    in: core
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: duplicatetype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions