Hello,

we are using in xsltforms upload control and we found a performance
issue when uploading big files (with ~100000 lines).

Examining applet code, we have found a botteneck creating string in
base64 encoding.

We have solved the problem using StringBuilders instead of Strings in
for loops (I send you our changes attached in this email). Using Strings
in for loops is discouraged because in each iteration it is created a
new String with all the content.

In previous version, it lasted more than hour to load file, and now it
is almost immediate.

Regards,
Javier















************************************************************************************************************************************************
*La información contenida en este mensaje de correo electrónico es confidencial 
y puede revestir el carácter de reservada.   *
*Está dirigida exclusivamente a la persona destinataria.                        
                                                                           *
*El acceso o cualquier uso por parte de cualquier otra persona de este mensaje 
no están autorizados y pueden ser ilegales.*
*Si no es Ud. la persona destinataria, le rogamos que proceda a borrarlo.       
                                                                   *
*The information in this e-mail is confidential and may be legally privileged.  
                                                                      *
*It is intended solely for the addressee.                                       
                                                                                
    *
*Access or any use by any other person to this Internet e-mail is not 
authorised and may be unlawful.                                 *
*If you are not the intended recipient, please delete this e-mail.              
                                                                           *
************************************************************************************************************************************************
 
--- xsltforms.java	(revisión: 573)
+++ xsltforms.java	(copia de trabajo)
@@ -81,7 +81,7 @@
 					fs.close();
 					if (xsdtype.equals("base64Binary")) {
 						String s1 = new String(buffer, 0, efflength, encoding);
-						String s2 = new String("");
+						StringBuilder s2 = new StringBuilder("");
 						String codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 						for (int i = 0; i < s1.length(); i += 3) {
 							char c[] = new char[4];
@@ -93,21 +93,21 @@
 							c[1] = codes.charAt((b >> 12) & 0x3f);
 							c[2] = i < s1.length()-1 ? codes.charAt((b >> 6) & 0x3f) : '=';
 							c[3] = i < s1.length()-2 ? codes.charAt(b & 0x3f) : '=';
-							s2 += new String(c);
+							s2.append(c);
 						}
-						return s2;
+						return s2.toString();
 					} else if (xsdtype.equals("hexBinary")) {
 						String s1 = new String(buffer, 0, efflength, encoding);
-						String s2 = new String("");
+						StringBuilder s2 = new StringBuilder("");
 						for (int i = 0; i < s1.length(); i++) {
 							char c[] = new char[2];
 							char c1 = (char)((s1.charAt(i) >> 4) & 0xF);
 							c[0] = (char)(c1 < 10 ? '0'+c1 : 'A'-10+c1);
 							char c2 = (char)(s1.charAt(i) & 0xF);
 							c[1] = (char)(c2 < 10 ? '0'+c2 : 'A'-10+c2);
-							s2 += new String(c);
+							s2.append(c);
 						}
-						return s2;
+						return s2.toString();
 					} else {
 						return new String(buffer, 0, efflength, encoding);
 					}
@@ -121,7 +121,8 @@
 		if (data.length() > 100*1024*1024) {
 			return 0;
 		}
-		String s = new String("");
+		StringBuilder s = new StringBuilder("");
+		String s2 = null;
 		if (xsdtype.equals("base64Binary")) {
 			if (data.length() % 4 != 0) {
 				return 0;
@@ -137,16 +138,17 @@
 				char c3 = data.charAt(i+3);
 				b += c3 == '=' ? 0 : (c3 == '/' ? 63 : c3 == '+' ? 62 : c3 < 'A' ? c3+52-'0' : c3 < 'a' ? c3-'A' : c3+26-'a') & 0x3f;
 				c[0] = (char)(b >> 16);
-				s += new String(c);
+				s.append(c);
 				if (data.charAt(i+2) != '=') {
 					c[0] = (char)((b >> 8) & 0xff);
-					s += new String(c);
+					s.append(c);
 				}
 				if (data.charAt(i+3) != '=') {
 					c[0] = (char)(b & 0xff);
-					s += new String(c);
+					s.append(c);
 				}
 			}
+			s2 = s.toString();
 		} else if (xsdtype.equals("hexBinary")) {
 			if (data.length() % 2 == 1) {
 				return 0;
@@ -154,12 +156,13 @@
 			for (int i = 0; i < data.length(); i += 2) {
 				char c[] = new char[1];
 				c[0] = (char)(((data.charAt(i) < 'A' ? data.charAt(i)-'0' : data.charAt(i)+10-'A') << 4) + ((data.charAt(i+1) < 'A' ? data.charAt(i+1)-'0' : data.charAt(i+1)+10-'A') & 0xf));
-				s += new String(c);
+				s.append(c);
 			}
+			s2 = s.toString();
 		} else {
-			s = data;
+			s2 = data;
 		}
-		final String finaldata = s;
+		final String finaldata = s2;
 		return ((Integer)AccessController.doPrivileged(new PrivilegedAction() {
 			public Object run() {		
 				try {
@@ -224,4 +227,4 @@
 			}
 		})).intValue();
 	}
-}
\ No hay ningún carácter de nueva línea al final del fichero
+}

<<attachment: jdiaz.vcf>>

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Xsltforms-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xsltforms-support

Reply via email to