PB 6.21 b2 - EditorGadget behaving strangely

Just starting out? Need help? Post your questions and find answers here.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

PB 6.21 b2 - EditorGadget behaving strangely

Post by Blue »

PB version : 6.21, beta 4, under Windows 11 x64
Purpose : displaying and redisplaying many lines of text loaded into a gadget.
Means : originally using an EditorGadget, switched to a ListViewGadget.

When using a ListViewGadget, no problem. Fast and stable. The time to display the lines of text varies very little, no matter how many times the lines of text get read/erased, then read again into the gadget.

However, with an EditorGadget, strange things happen. The time required for displaying the lines of text keeps increasing over each iteration, until the process eventually just crawls. The strangest thing, however, is that, when closing the app after running it in the normal course of its development, the IDE's tab for the app experiences a very noticeable delay before returning to normal and becoming usable again. That behaviour affects ONLY the app's source code tab, none of the others. So, something is obviously happening behind the scene, but I haven't a clue what it is. This never happens when using the ListViewGadget in the same source code.

Sample code that verifies this anomaly :

Code: Select all

; ***************************
; :: Blue April 2025 ::
; ***************************
; change this value to choose the gadget used to display the test data
  #liste = 0            ;-  0=EditorGadget,  1=ListViewGadget  

EnableExplicit
Enumeration             ;- gadget constants 
  #zz_nLines_LABEL
  #zz_nLines
  #zz_TXT_gadgetType
  #zz_CMD_Go
  #zz_Display
  #zz_TXT_infos
EndEnumeration

Procedure DisplayText()
  Static test
  test + 1 
  Protected maxLines, prevTestValue, line$
  Protected gadget$
  If #liste 
    gadget$ = "ListViewGadget "
  Else
    gadget$ = "EditorGadget "
  EndIf
  
  DisableGadget(#zz_CMD_Go,1)
  SetGadgetText(#zz_CMD_Go,"..")
  
  #zz_TIME_ms$ = "[ms]> "
  
  maxLines = Val(GetGadgetText(#zz_nLines))
  If 0 = CountGadgetItems(#zz_Display)
    SetGadgetText(#zz_TXT_infos, #zz_TIME_ms$ )
    Debug "; "+maxLines + " lines in " +gadget$ +" :"
  Else
    prevTestValue = CountGadgetItems(#zz_Display)
    ClearGadgetItems(#zz_Display)
    If maxLines <> prevTestValue
      Debug ""
      Debug "; "+maxLines + " lines in " +gadget$ +" :"
      test = 1
      SetGadgetText(#zz_TXT_infos, #zz_TIME_ms$)
    EndIf
  EndIf

  Protected line, count, lapsed
  SetActiveGadget(#zz_Display)
  lapsed = ElapsedMilliseconds()            ; start tracking time 
  While line < maxLines
    line + 1
    line$ = "Line " + line +" of " + maxLines 
    AddGadgetItem (#zz_Display, -1, "Test #" +test +" : " + line$)
    count + 1
    If count = 24
      count = 0
      SetGadgetText(#zz_CMD_Go,Str(line))
    EndIf
  Wend
  lapsed = ElapsedMilliseconds() - lapsed   ; stop  tracking time
  SetGadgetState(#zz_Display, line-1) ; go to the last line
  
  If test > 5
    test = 1
    SetGadgetText(#zz_TXT_infos, #zz_TIME_ms$ )
  EndIf
  SetGadgetText(#zz_TXT_infos, GetGadgetText(#zz_TXT_infos) + "[" +lapsed +"]  ")
  Debug "; time " + GetGadgetText(#zz_TXT_infos)

  DisableGadget(#zz_CMD_Go,0)
  SetGadgetText(#zz_CMD_Go,"Again")
EndProcedure
Procedure CreerDialogue()
  #winW = 400
  #winH = 600
  #winType = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

  If 0 = OpenWindow(0, 0, 0, #winW, #winH, "TESTing listing gadgets", #winType)
    MessageRequester("ERROR", "Couldn't open a window...")
    End
  EndIf

  #marge = 10
  Protected gi, gX,gY, gW,gH

  gi = #zz_nLines_LABEL
    gH = 20
    gW = 48
    gY = #marge
    gX = #marge
    TextGadget(gi,gX,gY,gW,gH,"Display")

  gi = #zz_nLines
    gX + gW
    gW = 56
    ComboBoxGadget(gi,gX,gY,gW,gH)  ;- ..test values
      Protected i
      AddGadgetItem(gi, -1,"16")
      For i = 0 To 8
        AddGadgetItem(gi, -1,Str(128*Pow(2,i)))
      Next
      SetGadgetState(gi,6)    ; default : 1024 lines

  gi = #zz_TXT_gadgetType
    gX + gW + 6
    gW = #winW - #marge - gX
    TextGadget(gi,gX,gY,gW,gH,"")
    If #liste 
      SetGadgetText(gi,"lines in a ListViewGadget" )
    Else
      SetGadgetText(gi,"lines in an EditorGadget" )
    EndIf

  gi = #zz_CMD_Go
    gY + gH + 2
    gW = 70
    gX = #winW -#marge -gW 
    ButtonGadget(gi,gX,gY,gW,gH,"Start")

  gi = #zz_TXT_infos
    gW = gX -#marge -4
    gX = #marge 
    TextGadget(gi,gX,gY,gW,gH,"The time [in ms] for each run will be shown here.")
    SetGadgetColor(gi,#PB_Gadget_BackColor,#Yellow)

  gi = #zz_Display
    gY + gH +4
    gW = #winW -#marge*2
    gH = #winH -#marge -gY -8
    If #liste ; beaucoup plus rapide
      ListViewGadget(gi,gX,gY,gW,gH)                     ;- ..ListViewGadget
    Else
      EditorGadget(gi,gX,gY,gW,gH,#PB_Editor_ReadOnly)   ;- ..EditorGadget
    EndIf
EndProcedure

  Debug "; - - - - - - - - - - - - - - - - - - - - - - - -"
  CreerDialogue()
  Define event
  Repeat                          ;- Events Loop
    event = WaitWindowEvent(1)
    Select event
      Case #PB_Event_CloseWindow : Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #zz_CMD_Go : DisplayText()
        EndSelect
    EndSelect  
  ForEver
  Debug "; - - - - - - - - - - - - - - - - - - - - - - - -"
  Debug ""
  Debug ""
  End
possibly related to EditorGadget clearing bug
Last edited by Blue on Sat Apr 12, 2025 6:53 pm, edited 1 time in total.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Fred »

You're not processing the event loop anymore when filling the gadget, that's why the UI locks.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Blue »

Fred wrote: Fri Apr 11, 2025 9:25 am You're not processing the event loop anymore when filling the gadget, that's why the UI locks.
I'll gladly take your word for that... but could you be more specific ?
How should i process the events loop while filling the gadget ?

I don't understand that...
   ... filling a ListViewGadget goes without a hitch,
   ... filling an EditorGadget does not go well,
with the very same code !
How can the same events processing be right with a gadget, but be wrong with the other ?

Check how times increase over each run with EditorGadget :
; - - - - - - - - - - - - - - - - - - - - - - - -
; 1024 lines
; EditorGadget: [4974]  [5433]  [5812] [6196]  [6533]
;                                  +459   +838     +1222   +1559
;                                  +9.2%  +16.8% +24.6%  +31.3%
; - - - - - - - - - - - - - - - - - - - - - - - -
; 2048 lines
; EditorGadget: [11018]  [12573] [14183]  [16905]  [20609]
;                                    +1555    +3165    +5887    +9591
;                                    +14.1%   +28.7%  +53.4%   +87.0%
; - - - - - - - - - - - - - - - - - - - - - - - -
; 4096 lines
; EditorGadget:  [28098]  [35598]  [45752]  [56648]  [75756]
;                                      +7500   +17654   +28550    +47658
;                                      +26.7%  +62.8%   +101.6%  +169.6%
; - - - - - - - - - - - - - - - - - - - - - - - -
; 8192 lines
;   EditorGadget: [97822]  [134104]  [196993]  [306193]  [384424]
;                                     +36282      +99171    +208371  +286602
;                                      +37.1%     +101.4%   +213.0%  +293.0%
; - - - - - - - - - - - - - - - - - - - - - - - -

while times using the ListViewGadget remain near identical between each run.

Also, when the EditorGadget is selected for testing, the source code tab hangs when the test code window closes after running from within the IDE. No such thing happens when using the ListViewGadget. The way events are being processed has nothing to do with this phenomenon.

I think you missed the point here.
The issue you adressed was not the issue raised.
I was not looking for a way to display the contents of the display gadget while filling it with test data.
I was pointing out a malfunction in the EditorGadget
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Fred »

It's because the editor is slower to update but you lock the event loop in both case.

try this, the event are just flushed during the updated (you should handle them in real apps):

Code: Select all

; ***************************
; :: Blue April 2025 ::
; ***************************
; change this value to choose the gadget used to display the test data
  #liste = 0            ;-  0=EditorGadget,  1=ListViewGadget  

EnableExplicit
Enumeration             ;- gadget constants 
  #zz_nLines_LABEL
  #zz_nLines
  #zz_TXT_gadgetType
  #zz_CMD_Go
  #zz_Display
  #zz_TXT_infos
EndEnumeration

Procedure DisplayText()
  Static test
  test + 1 
  Protected maxLines, prevTestValue, line$
  Protected gadget$
  If #liste 
    gadget$ = "ListViewGadget "
  Else
    gadget$ = "EditorGadget "
  EndIf
  
  DisableGadget(#zz_CMD_Go,1)
  SetGadgetText(#zz_CMD_Go,"..")
  
  #zz_TIME_ms$ = "[ms]> "
  
  maxLines = Val(GetGadgetText(#zz_nLines))
  If 0 = CountGadgetItems(#zz_Display)
    SetGadgetText(#zz_TXT_infos, #zz_TIME_ms$ )
    Debug "; "+maxLines + " lines in " +gadget$ +" :"
  Else
    prevTestValue = CountGadgetItems(#zz_Display)
    ClearGadgetItems(#zz_Display)
    If maxLines <> prevTestValue
      Debug ""
      Debug "; "+maxLines + " lines in " +gadget$ +" :"
      test = 1
      SetGadgetText(#zz_TXT_infos, #zz_TIME_ms$)
    EndIf
  EndIf

  Protected line, count, lapsed
  SetActiveGadget(#zz_Display)
  lapsed = ElapsedMilliseconds()            ; start tracking time 
  While line < maxLines
    line + 1
    line$ = "Line " + line +" of " + maxLines 
    AddGadgetItem (#zz_Display, -1, "Test #" +test +" : " + line$)
    count + 1
    If count % 24 = 0
      SetGadgetText(#zz_CMD_Go,Str(line))
      While WindowEvent() : Wend ; Flush the events
    EndIf
  Wend
  lapsed = ElapsedMilliseconds() - lapsed   ; stop  tracking time
  SetGadgetState(#zz_Display, line-1) ; go to the last line
  
  If test > 5
    test = 1
    SetGadgetText(#zz_TXT_infos, #zz_TIME_ms$ )
  EndIf
  SetGadgetText(#zz_TXT_infos, GetGadgetText(#zz_TXT_infos) + "[" +lapsed +"]  ")
  Debug "; time " + GetGadgetText(#zz_TXT_infos)

  DisableGadget(#zz_CMD_Go,0)
  SetGadgetText(#zz_CMD_Go,"Again")
EndProcedure
Procedure CreerDialogue()
  #winW = 400
  #winH = 600
  #winType = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

  If 0 = OpenWindow(0, 0, 0, #winW, #winH, "TESTing listing gadgets", #winType)
    MessageRequester("ERROR", "Couldn't open a window...")
    End
  EndIf

  #marge = 10
  Protected gi, gX,gY, gW,gH

  gi = #zz_nLines_LABEL
    gH = 20
    gW = 48
    gY = #marge
    gX = #marge
    TextGadget(gi,gX,gY,gW,gH,"Display")

  gi = #zz_nLines
    gX + gW
    gW = 56
    ComboBoxGadget(gi,gX,gY,gW,gH)  ;- ..test values
      Protected i
      AddGadgetItem(gi, -1,"16")
      For i = 0 To 8
        AddGadgetItem(gi, -1,Str(128*Pow(2,i)))
      Next
      SetGadgetState(gi,6)    ; default : 1024 lines

  gi = #zz_TXT_gadgetType
    gX + gW + 6
    gW = #winW - #marge - gX
    TextGadget(gi,gX,gY,gW,gH,"")
    If #liste 
      SetGadgetText(gi,"lines in a ListViewGadget" )
    Else
      SetGadgetText(gi,"lines in an EditorGadget" )
    EndIf

  gi = #zz_CMD_Go
    gY + gH + 2
    gW = 70
    gX = #winW -#marge -gW 
    ButtonGadget(gi,gX,gY,gW,gH,"Start")

  gi = #zz_TXT_infos
    gW = gX -#marge -4
    gX = #marge 
    TextGadget(gi,gX,gY,gW,gH,"The time [in ms] for each run will be shown here.")
    SetGadgetColor(gi,#PB_Gadget_BackColor,#Yellow)

  gi = #zz_Display
    gY + gH +4
    gW = #winW -#marge*2
    gH = #winH -#marge -gY -8
    If #liste ; beaucoup plus rapide
      ListViewGadget(gi,gX,gY,gW,gH)                     ;- ..ListViewGadget
    Else
      EditorGadget(gi,gX,gY,gW,gH,#PB_Editor_ReadOnly)   ;- ..EditorGadget
    EndIf
EndProcedure

  Debug "; - - - - - - - - - - - - - - - - - - - - - - - -"
  CreerDialogue()
  Define event
  Repeat                          ;- Events Loop
    event = WaitWindowEvent(1)
    Select event
      Case #PB_Event_CloseWindow : Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #zz_CMD_Go : DisplayText()
        EndSelect
    EndSelect  
  ForEver
  Debug "; - - - - - - - - - - - - - - - - - - - - - - - -"
  Debug ""
  Debug ""
  End
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Blue »

Fred wrote: Mon Apr 14, 2025 9:41 am It's because the editor is slower to update but you lock the event loop in both case.

try this, the event are just flushed during the updated (you should handle them in real apps):

Code: Select all

;[...]
Procedure DisplayText()
;[...]
    If count % 24 = 0
      SetGadgetText(#zz_CMD_Go,Str(line))
      While WindowEvent() : Wend ; Flush the events
    EndIf
;[...]
EndProcedure
;[...]
Indeed, that one line of code

Code: Select all

    While WindowEvent() : Wend                  ; Flush the events[/color]
makes quite a difference. No more Windows "Not responding" message when shifting the focus away and then back to the app.
That's a piece of code I never even thought of using before. So, thank you for the lesson in proper programming.
Thank you as well for taking the time to precisely pinpoint the error.
I would never have spotted it by myself, much less found the answer !
Much appreciated.

However, a bug definitely remains. The above correction does not address the EditorGadget issues of
     1. increasing its processing times over each consecutive run with large numbers of data
     2. the delayed return to normal of the IDE's source tab after running the app
Something untoward is happening with this gadget.
And, again, none of this happens with the ListViewGadget, no matter if the events get flushed or not.

I think this topic should return to the Bugs section.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Fred »

The editor gadget is not meant to have many item added as it gets the whole buffer and add it at the end at every call, that's why it gets slower the more your add it to it. The delay to return to the IDE is because it's using much more memory than ListIconGadget()
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by HeX0R »

Blue wrote: Mon Apr 14, 2025 4:45 pm However, a bug definitely remains. The above correction does not address the EditorGadget issues of
     1. increasing its processing times over each consecutive run with large numbers of data
     2. the delayed return to normal of the IDE's source tab after running the app
Something untoward is happening with this gadget.
And, again, none of this happens with the ListViewGadget, no matter if the events get flushed or not.

I think this topic should return to the Bugs section.
What is a large number of data?
I see no real difference with 4096 lines:

Code: Select all

[17:55:49] ; - - - - - - - - - - - - - - - - - - - - - - - -
[17:55:50] ; 4096 lines in EditorGadget  :
[17:55:53] ; time [ms]> [3057]  
[17:55:59] ; time [ms]> [3057]  [3253]  
[17:56:08] ; time [ms]> [3057]  [3253]  [3140]  
[17:56:13] ; time [ms]> [3057]  [3253]  [3140]  [3193]  
[17:56:20] ; time [ms]> [3057]  [3253]  [3140]  [3193]  [3152]  
[17:56:31] ; - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Blue »

HeX0R wrote: Mon Apr 14, 2025 5:02 pm What is a large number of data?
I see no real difference with 4096 lines:
That’s interesting indeed.
But I can’t think of a better answer than "just try a larger value…".
As for my numbers, i can only report on the values that I get back on my PC. Maybe it’s a very slow machine. :shock:

Still, I’m curious. I’d like to see the times you get when using the ListViewGadget.

In the end, though, in view of Fred’s latest reply in this post, the subject can only remain totally academic.
Last edited by Blue on Mon Apr 14, 2025 5:59 pm, edited 1 time in total.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Blue »

Fred wrote: Mon Apr 14, 2025 4:54 pm The editor gadget is not meant to have many item added as it gets the whole buffer and add it at the end at every call, that's why it gets slower the more your add it to it. The delay to return to the IDE is because it's using much more memory than ListIconGadget()
So, no bug.
The continuous stacking of data in memory as the contents change is just normal behaviour for the EditorGadget ?
I must say that surprises me greatly, but at least now I know.
Thank you for the clarification.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by HeX0R »

Blue wrote: Mon Apr 14, 2025 5:41 pm Still, I’m curious. I’d like to see the times you get when using the ListViewGadget.
In the end, though, in view of Fred’s latest reply in this post, the subject can only remain totally academic.
Around 1400ms each run.
But I must admit, I fooled a little bit, because, frankly speaking this example doesn't make much sense.
If you fill an Editor with so many lines as fast as possible, there is no need to keep it editable (only Speedy Gonzales could maybe edit the content while filling), therefore I disabled it before filling and enabled it later.
But there are even better possibilities to speed it up.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: PB 6.21 b2 - EditorGadget behaving strangely

Post by Blue »

I fully agree with you. There are better ways.
But don’t knock this tiny app.
Once the EditorGadget had been replaced with the much speedier ListViewGadget, it ended up being spot on for dealing with data in the research project.
Oh, and the enabling of the editing ability was only for the testing phase.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply