11-09-2018, Saat: 23:17
Merhaba, uygulama geliştirken karşılaştığım küçük hızlandırma ipuçlarını sizlerle paylaşıyorum. Sizde aklınıza gelenleri paylaşarak katkıda bulunabilirsiniz.
1-) Combobox gibi nesnelerde görsel değişikliği itemsları yüklemeden yapın.
2-) Begin Update kullanın
3-) Dinamik nesne oluşturduğunuzda parentinin visible değerini false yapın
4-) Items Bitiş değerini biliyorsanız Count kullanmayın
1-) Combobox gibi nesnelerde görsel değişikliği itemsları yüklemeden yapın.
var Ind : Integer; Sure : TDateTime; begin Caption := ''; Sure := Now; ComboTest.Style := TComboBoxStyle.csDropDownList; // Eklemeden önce yaptık for Ind := 0 to 20000 do begin ComboTest.Items.Add(IntToStr(Ind)); end; Caption := MilliSecondsBetween(now,Sure).ToString; // 1450 milli second end;
var Ind : Integer; Sure : TDateTime; begin Caption := ''; Sure := Now; for Ind := 0 to 20000 do begin ComboTest.Items.Add(IntToStr(Ind)); end; ComboTest.Style := TComboBoxStyle.csDropDownList; // Eklemeden sonra yaptık Caption := MilliSecondsBetween(now,Sure).ToString; // 2062 milli second end;
2-) Begin Update kullanın
var Ind : Integer; Sure : TDateTime; begin Caption := ''; Sure := Now; ComboTest.Items.BeginUpdate; //VCL için beginupdate ekledik for Ind := 0 to 20000 do begin ComboTest.Items.Add(IntToStr(Ind)); end; ComboTest.Items.EndUpdate; Caption := MilliSecondsBetween(now,Sure).ToString; // 382 milli second end;
var Ind : Integer; Sure : TDateTime; begin Caption := ''; Sure := Now; for Ind := 0 to 20000 do begin ComboTest.Items.Add(IntToStr(Ind)); end; Caption := MilliSecondsBetween(now,Sure).ToString; // 1454 milli second end;
3-) Dinamik nesne oluşturduğunuzda parentinin visible değerini false yapın
var xEdit : array of TEdit; Ind : Integer; Sure : TDateTime; begin SetLength(xEdit,500); Sure := Now; for Ind := Low(xEdit) to High(xEdit) do begin xEdit[Ind] := TEdit.Create(PanelTest); xEdit[Ind].Parent := PanelTest; end; Caption := millisecondsbetween(Now,Sure).ToString; // 680 milli second end;
var xEdit : array of TEdit; Ind : Integer; Sure : TDateTime; begin SetLength(xEdit,500); Sure := Now; PanelTest.Visible := False; try for Ind := Low(xEdit) to High(xEdit) do begin xEdit[Ind] := TEdit.Create(PanelTest); xEdit[Ind].Parent := PanelTest; end; finally PanelTest.Visible := True; end; Caption := millisecondsbetween(Now,Sure).ToString; // 550 milli second end;
4-) Items Bitiş değerini biliyorsanız Count kullanmayın
var Ind : Integer; Sure : TDateTime; begin Sure := Now; for Ind := 0 to Pred(Memo1.Lines.Count) do // Count ile aldık Caption := Ind.ToString; Caption := MilliSecondsBetween(Now,Sure).ToString; // 638 milli second end;
var Ind : Integer; Sure : TDateTime; begin Sure := Now; for Ind := 0 to 20000 do // Adet Girdik Caption := Ind.ToString; Caption := MilliSecondsBetween(Now,Sure).ToString; // 521 milli second end;
Yalnızım ama bir kente yürüyen ordu gibiyim, edebiyattan kaçınmalıyım..