What were you trying to do that didn't work?
A performance regression is noticed in Python 3 where the same code execution and operations take considerable less time on Python2 on RHEL 8.X
How reproducible:
The issue is reproducible consistently on RHEL 8.x <–> I have already tested it on both RHEL 8.8 and RHEL 8.9
Steps to reproduce
- Using the below code, when the program is executed for python2 and python3 seperately, a window opens.
- Press on the button and a contextual menu will appear.
- You must look in the trace/output “DESPUES DE MOSTRAR” which will appear in the console each time the button is pressed, and it indicates the time spent to show the dropdown.
Python2 code -
import time
import gtk
from datetime import datetime
def f_show_elapsed(x, y):
delta = y - x
return "%s.%s" % (delta.seconds, delta.microseconds)
def on_button_clicked(widget, event):
e = datetime.now()
print "ENTRO"
menu1 = gtk.Menu()
item1 = gtk.MenuItem("Modify")
item1.connect("activate", printed)
item1.show_all()
item2 = gtk.MenuItem("Load")
item2.connect("activate", printed)
item2.show_all()
item3 = gtk.MenuItem("Modify")
item3.connect("activate", printed)
item3.show_all()
item4 = gtk.MenuItem("Load")
item4.connect("activate", printed)
item4.show_all()
item5 = gtk.MenuItem("Modify")
item5.connect("activate", printed)
item5.show_all()
item6 = gtk.MenuItem("Load")
item6.connect("activate", printed)
item6.show_all()
menu1.append(item1)
menu1.append(item2)
menu1.append(item3)
menu1.append(item4)
menu1.append(item5)
menu1.append(item6)
a = datetime.now()
print "ANTES DE MOSTRAR", f_show_elapsed(e, a)
menu1.popup(None, None, None, event.button, event.time)
d = datetime.now()
print "DESPUES DE MOSTRAR", f_show_elapsed(a, d)
def printed(widget):
print "printtttt"
window = gtk.Window()
window.set_title("Ejemplo de GTK con Python")
window.set_default_size(400, 200)
button = gtk.Button(label="Haz clic-")
button.connect("button-press-event", on_button_clicked)
box = gtk.VBox(spacing=6)
box.pack_start(button, True, True, 0)
window.add(box)
window.connect("delete-event", gtk.main_quit)
window.show_all()
gtk.main()
Python 3 code -
import gi
import time
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk,Gdk
from datetime import datetime
def f_show_elapsed(x,y):
delta = y-x
return "%s.%s" %(delta.seconds,delta.microseconds)
def on_button_clicked(widget,event):
e = datetime.now()
print ("ENTRO")
menu1 = Gtk.Menu()
item1 = Gtk.MenuItem("Modify")
item1.connect("activate", printed)
item1.show_all()
item2 = Gtk.MenuItem("Load")
item2.connect("activate", printed)
item2.show_all()
item3 = Gtk.MenuItem("Modify")
item3.connect("activate", printed)
item3.show_all()
item4 = Gtk.MenuItem("Load")
item4.connect("activate", printed)
item4.show_all()
item5 = Gtk.MenuItem("Modify")
item5.connect("activate", printed)
item5.show_all()
item6 = Gtk.MenuItem("Load")
item6.connect("activate", printed)
item6.show_all()
menu1.append(item1)
menu1.append(item2)
menu1.append(item3)
menu1.append(item4)
menu1.append(item5)
menu1.append(item6)
a=datetime.now()
print ("ANTES DE MOSTRAR", f_show_elapsed(e,a))
menu1.popup(None, None, None, None, event.button, event.time)
d=datetime.now()
print ("DESPUES DE MOSTRAR", f_show_elapsed(a,d))
def printed(widget):
print("printtttt")
window = Gtk.Window(title="Ejemplo de GTK con Python")
window.set_default_size(400, 200)
button = Gtk.Button(label="Haz clic-")
button.connect("button-press-event", on_button_clicked)
box = Gtk.VBox(spacing=6)
#box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
box.pack_start(button, True, True, 0)
window.add(box)
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
Expected results
The latency of the code execution is a bit flaky in python3. The latency ranges anywhere from 0.300 to 0.800 and sometimes as high as 0.900.
I have not seen this behavior with python2. It executes the code with a consistent latency of 0.200 with a deviance of ± 0.100.
At this point, I feel that this could be happening due to the additional library that is being imported; due to which additional code and functions are having to execute in the background adding to the latency of code execution.
From this, I see this to be an issue on python's end, and may not be related to the OS side of things.
Actual results
Need to confirm this is not an issue on the OS end, and understand why python 3 is taking so long on RHEL8.x for execution. (Regression in code execution)