Opened 4 years ago

Closed 4 years ago

#2338 closed defect (fixed)

Petascope - String concatenation is much slower than StringBuilder

Reported by: Bang Pham Huu Owned by: Bang Pham Huu
Priority: major Milestone: 10.0
Component: petascope Version: 9.8
Keywords: Cc: Dimitar Misev, Vlad Merticariu
Complexity: Medium

Description

This problem happens for example with WMS GetCapabilities for ten thousands of Layers (each layer is generated to XML string).

In a loop to concatenate the XML string, with a = a + b it takes

real	1m48.479s

With StringBuilder to concatenate these strings in a loop, it will take:

real	0m3.223s

Change History (3)

comment:1 by Dimitar Misev, 4 years ago

Even 3s is a lot. You should precalculate the total length of the XML strings should be concatenated, and then set the capacity of the StringBuilder to this total length.

https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#StringBuilder(int)

comment:2 by Bang Pham Huu, 4 years ago

How can I suppose to precalculate when the string size of a WMS layer is varied in each loop?

comment:3 by Bang Pham Huu, 4 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.