简体   繁体   English

使用Spring MVC在模型中添加多个属性会导致性能问题吗?

[英]Will adding multiple attributes in model leads to performance issues using Spring MVC?

Nearly 50 attributes are set to Model object, which includes lists, enums, strings 将近50个属性设置为Model对象,其中包括列表,枚举,字符串

model.addAttribute("casetype", Casetype.values());
model.addAttribute("caseStatus", CaseStatus.values());

This is common code which execute for every controller but for all controller we need only 4 - 5 attrbutes and all other 45 attribute are of no use. 这是为每个控制器执行的通用代码,但对于所有控制器,我们只需要4-5个属性,而其他所有45个属性都没有用。

Will there be any performance benefit if we remove these 45 attributes, or let it remain as it is for all controllers? 如果我们删除这45个属性,或者保留所有控制器的属性,是否会对性能产生任何好处?

The model is basically a HashMap<String, Object> . 该模型基本上是HashMap<String, Object> Every value you put into your Model will trigger a put operation on the HashMap . 您输入到模型中的每个值都将触发对HashMap的放置操作。 Put/Get operations on a HashMap are usually O(1) . HashMap上的放置/获取操作通常为 O(1) Putting all these values into the model does however take some computation power and these values will stay in memory while rendering your view and have to be garbage collected at some point. 但是,将所有这些值放入模型中确实需要一定的计算能力,并且这些值将在呈现视图时保留在内存中,并且必须在某些时候进行垃圾回收。

TLDR: Putting all those variables into your model does affect performance but it really depends on how large your application is and how often your endpoints are triggered. TLDR:将所有这些变量放入模型中确实会影响性能,但这实际上取决于应用程序的大小以及触发端点的频率。 If you need maximum performance you should strip off any redudant items from your model object, if it's just some users then you can probably leave it as is. 如果需要最高性能,则应从模型对象中删除所有多余的项,如果只有某些用户,则可以将其保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM