Matter template application with Optimize for speed (-O2) broken

Hi Folks.

I have been really frustrated with the NCS SDK for its fragility.
Matter Template application works with Optimize for debugging (-Og) an Optimize for size (-Os) but as soon I select Optimize for speed (-O2) the application doesn't work.
It seems like code never reaches AppTask::Init(). Its endlessly processing some worker queue, never sleeping (deciding based on current consumption).

Steps to reproduce (everything In VS Code nRF Connect extension):

  1. Welcome: Create a new application. -> Copy a sample -> Matter Template
  2. Applications: template -> Create new build configuration
    1. Configuration: select prj_release.conf
    2. Optimization level: Optimize for speed (-O2)
    3. -> Build Configuration
  3. Actions: Flash

Validation:
- Broken build (-O2):
The current jumps almost immediately to ~3.9 mA and stays there without any fluctuations. When trying to add it to Apple Home, no variations in current.
- OK build (-Os / Og): The current jumps up and down, mostly somewhere around ~0.7 mA and ~0.4 mA. Can be added to Apple Home on iPhone, current jumps wildly during provision process which is normal.

Same is also reproducible with prj.conf build. I haven't tested with prj_no_dfu.conf.


Environment:
nRF52840-DK PCA10056 3.0.2 2023.21 1050242811
Macbook Pro M2 Pro, 16 GB, Ventura 13.3
VSCode 
1.86.1
Nrf Connect Desktop v4.4.0
Toolchain manager v1.3.0
NCS v2.5.2 (also tested with v2.5.0, same behaviour)  - installed using Toolchain manager
Apple Home on iPhone 12 iOS 17.2.1
Current measured from nRF52840-DK's nRF Current Measurement port (SB40 was cut) using handheld digital multimeter on mA range (no burden voltage issue).