Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Terrible slowdown on .NET processing
Message
De
05/05/2006 11:31:56
 
 
À
05/05/2006 06:17:01
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01119485
Message ID:
01119622
Vues:
15
>(Not sure if this can be an exact explanation).
>Strings in .Net are reference types and immutable. That's when you concatanate a string with another new string is not simply added to the end of the other in memory, but a totally new string is created.
>Within each call you're effectively creating a series of new strings in memory + a new lcHtml string.
>.Net StringBuilder class is for things like this. Use it. It effectively optimizes the process and is fast. Yey another alternative is to create a stream and append to that stream. ie:
>
>Dim sb as new StringBuilder()
>sb.Append(lcHTML)
>                        If cCurrentField = "No_Claim" Then
>for 1 to 8
>  sb.AppendFormat(  "&ClaimNo={0}&MitTelAI={1}&Hd=1>", _
>              Trim(oRow("No_Claim")), _
>              LTrim(Str(oRow("AI")))   )
>next
>                        End If
>
>or: If you prefer:
>sb.Append("&ClaimNo=")
>sb.Append(Trim(oRow("No_Claim")))
>sb.Append("&MitTelAI=")

The StringBuilder() does not resolve the issue. If I have this, which means I am not executing anything, I obtain a processing time of one second:
                        ' Process the hyperlinks, if any
                        'lcHtml = lcHtml + Hyperlink()
                        If cCurrentField = "No_Claim" Then
                            Dim sb As StringBuilder = New StringBuilder()
                            If False Then
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                sb.Append(oRow("No_Claim").ToString.Trim)
                                lcHtml = lcHtml + sb.ToString
                            End If
                        End If
If I remove the If False condition, I obtain a processing time of 7 seconds.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform