Date: Fri, 11 Mar 2005 12:32:24 +0000 Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: Inserting rows into GTree.tree_store is slow Message-ID: <20050311123224.GA786 at furbychan.cocan.org> References: <20050311003216.GA31634 at furbychan.cocan.org> <423167AC.5060900 at wanadoo.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline In-Reply-To: <423167AC.5060900 at wanadoo.fr> From: Richard Jones --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 11, 2005 at 05:41:00PM +0800, Arnold wrote: > Inserting a lot of rows is quite slow if a #GTree.model is "attached" to > a GTree.View. Thanks for the various tips. Detaching the model from the view didn't actually make much difference, but as a result of testing this I found the real problem, and it appears to be an issue in lablgtk2 itself. The attached program demonstrates the problem. In that program, each tree row has a "hidden" data cell of type Gobject.Data.caml. It appears that this hidden cell is causing the performance problems. Without the data cell, the test takes 11 second to insert 50,000 rows. With the data cell, the test takes 192 seconds to insert 50,000 rows. The slowdown factor is around x 17. Unfortunately my original program kind of depends quite fundamentally on having the hidden data cell. Any suggestions for ways to speed it up would be useful. Thanks, Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="test.ml" (* Test bulk insert into a tree_store. * To compile: * ocamlopt -w s -I +lablgtk2 unix.cmxa lablgtk.cmxa gtkInit.cmx test.ml -o test * After running, click the "Start test" button at the bottom of the window. * * Timings: * Simple implementation: 12.3s 12.4s 12.5s * Detach model from view during insert: 11.6s 11.4s 11.5s * Editable renderer: (same as before) * Added data column: 176s 192s *) let () = let window = GWindow.window ~width:800 ~height:600 () in let vbox = GPack.vbox ~packing:window#add () in (* The following code just creates the tree model / view. *) let sw = GBin.scrolled_window ~packing:(vbox#pack ~expand:true) ~hpolicy:`AUTOMATIC ~vpolicy:`AUTOMATIC () in let cols = new GTree.column_list in let name_col = cols#add Gobject.Data.string in let data_col = cols#add Gobject.Data.caml in let model = GTree.tree_store cols in let view = GTree.view ~model ~packing:sw#add () in view#selection#set_mode `MULTIPLE; let name_viewcol = let renderer = GTree.cell_renderer_text [] in GTree.view_column ~title:"Name" () ~renderer:(renderer, ["text", name_col]) in ignore (view#append_column name_viewcol); let button = GButton.button ~label:"Start Test" ~packing:vbox#pack () in let callback () = (* Start timing. *) let start = Unix.gettimeofday () in (* Insert 50,000 rows. *) model#clear (); view#set_model None; for i = 0 to 10 do let row = model#append () in model#set ~row ~column:name_col (string_of_int i); model#set ~row ~column:data_col i; for j = 0 to 50 do let row = model#append ~parent:row () in model#set ~row ~column:name_col (string_of_int j); model#set ~row ~column:data_col j; for k = 0 to 100 do let row = model#append ~parent:row () in model#set ~row ~column:name_col (string_of_int k); model#set ~row ~column:data_col k done done done; view#set_model (Some (model :> GTree.model)); (* Stop timing. *) let stop = Unix.gettimeofday () in let msg = Printf.sprintf "Total time: %gs" (stop -. start) in let title = "Results" in let icon = GMisc.image () in icon#set_stock `DIALOG_INFO; icon#set_icon_size `DIALOG; GToolbox.message_box ~title ~icon msg in ignore (button#connect#clicked ~callback); ignore (window#connect#destroy ~callback:GMain.quit); window#show (); GMain.main () --VbJkn9YxBvnuCH5J--