vbdavie Posted February 12 Share Posted February 12 I have this mainform with tons of tabs and controls and labels etc... It was taking about 17 seconds before i saw the page start to display on the screen. It worked fine, but the users were clicking refresh because they didn't think it was loading. They were impatient. So, i added a splash screen that displays almost immediately, but still about 17 seconds until the mainform displays. I tracked it down to the uniGUIApplication.pas JSPreProcess function. It consists of removing the /* and */ comments and then it removes the #3 and #4 characters. The first task was taking about 4 seconds and the second task was taking about 13 seconds. You can see that i modified the 1st task so that it takes less than a second instead of 4 seconds. function TUniGUISession.JSPreProcess(const JSCode: string): string; var I,J : Integer; // the following variables are added by DLR PCharS:PChar; PCharD:PChar; Delta:Integer; DeltaTmp:Integer; OrigLen:Integer; ResultAddr:PChar; LastByte:PChar; begin // DLR FASTER COMMENT REMOVAL Result := JSCode; ResultAddr:=@Result[1]; OrigLen:=Length(Result); LastByte:=PChar(Integer(@ResultAddr^)+OrigLen*SizeOf(Char)); Delta:=0; I := pos('/*', Result); while I <> 0 do begin // Extracts comments J := PosEx('*/', Result, I); if J>I then Begin //DLE PCharS:=ResultAddr; Inc(PCharS,I + (J - I + 2)-1); PCharD:=ResultAddr; Inc(PCharD,I-1); DeltaTmp:=((J+1) - (I) + 1); Delta:=Delta + DeltaTmp; // the move could be a little more efficient by not MOVING all the data, but it works fast Move(PCharS^,PCharD^,Integer(@LastByte^)-Integer(@PCharS^)); End else Inc(I, 2); I := PosEx('/*', Result, I); If I>OrigLen-Delta Then I:=0; end; //DLR SetLength(Result,OrigLen-Delta); Result := HandleJSReturns(Result); Result := AnsiReplaceStr(AnsiReplaceStr(Result, CommandDelim, ''), IdentDelim, ''); // Extracts aux delimiters end; You can see i use the MOVE instead of the DELETE operation. SO much more faster. THEN the 2nd task was calling the "AnsiReplaceStr" function which is terribly SLOW and was taking about 13 seconds So, I replaced that function with a replacement i found on the internet. So, i added this code BEFORE the "AnsiReplaceStr" usage. function AnsiReplaceStr(const AText, AFromText, AToText: string): string; begin //DLR Result:= StrUtilsEx.FastStringReplace(AText, AFromText, AToText, [rfReplaceAll]); // Result:= SysUtils.StringReplace(AText, AFromText, AToText, [rfReplaceAll]); end; Function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; Begin //DLR Result:= StrUtilsEx.FastStringReplace(S, OldPattern, NewPattern, [rfReplaceAll]); //Result:= SysUtils.StringReplace(S, OldPattern, NewPattern, [rfReplaceAll]); End; Of course you will have to include StrUtilsEx in your USES clause. You can see that my replacement functions call a different function in the StrUtilsEX.PAS module. It's much faster. Probably 15 times faster. So, now the 2nd task takes less than 1 second instead of the 13 seconds. The end result is that my splash screen is only displayed for about 4 seconds instead of 17. Great improvement. Keep in mind that this fix is EXTREMELY useful only for LARGE FORMS with tons of controls. You won't notice any difference on small forms. Now for the magic, I have attached the StrUtilsEX.PAS file for your pleasure. Have fun with faster loading forms. If UNIGUI would implement my changes or similar that would be great, OTHERWISE I/we have to update the UniGUIApplication.pas file each time we download a new version Davie StrUtilsEx.pas 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted February 12 Share Posted February 12 Hello, We will try to analyze. Thank you. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.