[550.54.14] Very bad performance due to bunch of reallocations during glcore initialization

Original problem was reported to telegram-desktop: Slow startup on X11 · Issue #27618 · telegramdesktop/tdesktop · GitHub
The problem is simple - when using nvidia linux drivers - startup of telegram-desktop application is very slow (about 30 seconds).
It gets down to /usr/lib/libnvidia-glcore.so.550.54.14 which makes A LOT of memory reallocations during library initialization.
It starts from 12kb and reallocates memory with increasing step of 4144 which is very weird behavior.
telegram-desktop uses scudo allocator (Scudo Hardened Allocator — LLVM 19.0.0git documentation) and he can’t perform as fast as glibc implementation - and this is a reason of slow startup.
The question is - why all this reallocations are needed?
Can this behavior be fixed/improved?

GDB backtrace:

#3  realloc (ptr=0x7fd2d7601350, size=5942496) at /usr/src/debug/telegram-desktop/tdesktop-4.15.2-full/Telegram/ThirdParty/scudo/wrappers_c.inc:150
#4  0x00007fd2db1e8ff4 in ??? () at /usr/lib/libnvidia-glcore.so.550.54.14
#5  0x00007fd2db1ffa61 in ??? () at /usr/lib/libnvidia-glcore.so.550.54.14
#6  0x00007fd2db74fa98 in ??? () at /usr/lib/libnvidia-glcore.so.550.54.14
#7  0x00007fd2db1f4d06 in ??? () at /usr/lib/libnvidia-glcore.so.550.54.14
#8  0x00007fd2dc925b6a in ??? () at /usr/lib/libGLX_nvidia.so.0
#9  0x00007fd2dc97f692 in ??? () at /usr/lib/libGLX_nvidia.so.0
#10 0x00007fffffffc6f0 in ??? ()
#11 0x00007fd3df23b710 in ??? ()
#12 0x0000000000000002 in ??? ()
#13 0x00007fd2dc925013 in ??? () at /usr/lib/libGLX_nvidia.so.0
#14 0x00007fd3df23b710 in ??? ()
#15 0x00007ffff7fcd175 in call_init (env=0x7fd2df210c10, argv=0x7fffffffda48, argc=-15456, l=0x7fd2dc9d6f98) at dl-init.c:60
#16 call_init (l=0x7fd2dc9d6f98, argc=-15456, argv=0x7fffffffda48, env=0x7fd2df210c10) at dl-init.c:26
#17 0x00007ffff7fcd2ac in _dl_init (main_map=0x7fd3df23b710, argc=2, argv=0x7fffffffda48, env=0x7fd2df210c10) at dl-init.c:121
#18 0x00007ffff7fc956e in __GI__dl_catch_exception (exception=exception@entry=0x0, operate=operate@entry=0x7ffff7fd3d80 <call_dl_init>, args=args@entry=0x7fffffffc550) at dl-catch.c:211
#19 0x00007ffff7fd3d26 in dl_open_worker (a=a@entry=0x7fffffffc6f0) at dl-open.c:829
#20 0x00007ffff7fc94e1 in __GI__dl_catch_exception (exception=exception@entry=0x7fffffffc6d0, operate=operate@entry=0x7ffff7fd3c90 <dl_open_worker>, args=args@entry=0x7fffffffc6f0) at dl-catch.c:237
#21 0x00007ffff7fd410c in _dl_open (file=0x7ffbdf212f10 "libGLX_nvidia.so.0", mode=<optimized out>, caller_dlopen=0x7fffe5527bc7 <__glXLookupVendorByName+1271>, nsid=<optimized out>, argc=2, argv=0x7fffffffda48, env=0x7fd2df210c10) at dl-open.c:905
#22 0x00007ffff08a53fc in dlopen_doit (a=a@entry=0x7fffffffc960) at dlopen.c:56
#23 0x00007ffff7fc94e1 in __GI__dl_catch_exception (exception=exception@entry=0x7fffffffc8c0, operate=0x7ffff08a53a0 <dlopen_doit>, args=0x7fffffffc960) at dl-catch.c:237
#24 0x00007ffff7fc9603 in _dl_catch_error (objname=0x7fffffffc918, errstring=0x7fffffffc920, mallocedp=0x7fffffffc917, operate=<optimized out>, args=<optimized out>) at dl-catch.c:256
#25 0x00007ffff08a4f07 in _dlerror_run (operate=operate@entry=0x7ffff08a53a0 <dlopen_doit>, args=args@entry=0x7fffffffc960) at dlerror.c:138
#26 0x00007ffff08a54b1 in dlopen_implementation (dl_caller=<optimized out>, mode=<optimized out>, file=<optimized out>) at dlopen.c:71
#27 ___dlopen (file=<optimized out>, mode=<optimized out>) at dlopen.c:81
#28 0x00007fffe5527bc7 in __glXLookupVendorByName (vendorName=<optimized out>) at ../libglvnd-v1.7.0/src/GLX/libglxmapping.c:428
#29 0x00007fffe552a415 in __glXLookupVendorByScreen (dpy=dpy@entry=0x7fe3df210c10, screen=screen@entry=0) at ../libglvnd-v1.7.0/src/GLX/libglxmapping.c:572
#30 0x00007fffe552b24c in __glXGetDynDispatch (screen=0, dpy=0x7fe3df210c10) at ../libglvnd-v1.7.0/src/GLX/libglxmapping.c:606
#31 glXChooseFBConfig (dpy=0x7fe3df210c10, screen=0, attrib_list=0x7feadf2809e0, nelements=0x7fffffffcb48) at ../libglvnd-v1.7.0/src/GLX/libglx.c:1484
#32 0x00007ffff1f56a05 in qglx_findConfig (display=0x7fe3df210c10, screen=0, format=..., highestPixelFormat=highestPixelFormat@entry=false, drawableBit=drawableBit@entry=1, flags=flags@entry=0)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/tools/qarraydatapointer.h:114
#33 0x00007fd2deceacc7 in QGLXContext::QGLXContext (this=0x7ff8df22d510, display=<optimized out>, screen=0x7fe7df202210, format=<optimized out>, share=0x0, this=<optimized out>, display=<optimized out>, screen=<optimized out>, format=<optimized out>, share=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp:201
#34 0x00007fd2decebf75 in QXcbGlxIntegration::createPlatformOpenGLContext (this=0x7fdddf26fc90, context=<optimized out>) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxintegration.cpp:158
#35 0x00007ffff1e80520 in QOpenGLContext::create (this=this@entry=0x7fffffffce20) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/gui/kernel/qopenglcontext.cpp:355
#36 0x00007fd2deca282e in checkBackend (checkContext=...) at /usr/src/debug/plasma-integration/plasma-integration-6.0.2/qt6/src/platformtheme/qtquickrenderersettings.cpp:43
#37 initializeRendererSessions () at /usr/src/debug/plasma-integration/plasma-integration-6.0.2/qt6/src/platformtheme/qtquickrenderersettings.cpp:66
#38 0x00007ffff0f3da5a in qt_call_pre_routines () at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/kernel/qcoreapplication.cpp:306
#39 QCoreApplicationPrivate::init (this=this@entry=0x7fe7df202410) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/kernel/qcoreapplication.cpp:914
#40 0x00007ffff1b74ac1 in QGuiApplicationPrivate::init (this=this@entry=0x7fe7df202410) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/gui/kernel/qguiapplication.cpp:1579
#41 0x00007ffff2cf53ee in QApplicationPrivate::init (this=0x7fe7df202410) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/widgets/kernel/qapplication.cpp:473
#42 0x00007ffff2cf5542 in QApplication::QApplication (this=this@entry=0x7fffffffd400, argc=@0x7fffffffd3c0: 1, argv=<optimized out>, this=<optimized out>, argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/widgets/kernel/qapplication.cpp:461
#43 0x0000555556be7b4b in Core::Sandbox::Sandbox (argv=<optimized out>, argc=@0x7fffffffd3c0: 1, this=0x7fffffffd400) at /usr/src/debug/telegram-desktop/tdesktop-4.15.2-full/Telegram/SourceFiles/core/sandbox.cpp:83
#44 Core::Launcher::executeApplication (this=this@entry=0x7fefdf223e90) at /usr/src/debug/telegram-desktop/tdesktop-4.15.2-full/Telegram/SourceFiles/core/launcher.cpp:579
#45 0x0000555556be9b6e in Core::Launcher::exec (this=0x7fefdf223e90) at /usr/src/debug/telegram-desktop/tdesktop-4.15.2-full/Telegram/SourceFiles/core/launcher.cpp:388
#46 0x0000555555c2e9ff in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/telegram-desktop/tdesktop-4.15.2-full/Telegram/SourceFiles/main.cpp:12

More details in original issue.