Okay, so this is not the best practice situation, but luckily I have an answer, so please bear with me.
I'm working on a rather large Delphi project with lots of external APIs used. Those APIs are plugged in different ways, including units wrapped into IFDEFs in the DPR itself, when they are platform-dependent. Having IFDEFs in DPR is a bad practice - sure, but it is handy to have all the units listed in the project tree to switch between them (rather than switch between projects).
So I was adding another alternative API implementation to the project and as usual - wrapped the existing solution units into the {$IFDEF SOME_API_DLL}
clause and a new solution units into another {$IFDEF SOME_API_EXE}
.
Anyways, I noticed soon after, that the IDE started to freeze semi-randomly after just 3-5min of coding, which is unbearable toll.. The IDE would hog one CPU (e.g. 13% on 8-core PC). I was able to isolate the cause to be invocation of "autocomplete", "code completion" (Ctrl+Space) and "jump to declaration (Ctrl+Click).
The main question is - what could cause the IDE to freeze on how to resolve this?
I'm using Delphi XE8, but switching to other versions didn't help. Unfortunately newer 10.3+ versions (with claimed rewritten Code Insight) could not be tested/used due to third-party components.
Thanks to the bug being well connected to the new API implementation, I was able to track down the cause. So it appears that IDE does not like DPR files with IFDEFs (old news), but the real bummer seems to be that IDE handles IFDEFs okay only if they wrap only one unit.
The hint to the solution was the Project Tree, which gets auto-updated with units in DPR, but it auto-included only the first units after the IFDEF. Apparently, thats what also throws off the track the auto-completion.
Bad DPR structure that causes IDE to freeze on code-completion:
{$IFDEF EXTAI_API_DLL}
KM_ExtAI_DLL in 'src\KM_ExtAI_DLL.pas',
KM_ExtAI_DLLs in 'src\KM_ExtAI_DLLs.pas',
KM_ExtAI_SharedTypes in 'src\KM_ExtAI_SharedTypes.pas',
KM_ExtAI_SharedInterfaces in 'src\KM_ExtAI_SharedInterfaces.pas',
KM_ExtAIActions in 'src\KM_ExtAIActions.pas',
KM_ExtAIMaster in 'src\KM_ExtAIMaster.pas',
KM_ExtAIStates in 'src\KM_ExtAIStates.pas',
KM_ExtAIUtils in 'src\KM_ExtAIUtils.pas',
{$ENDIF}
Good DPR structure that lets IDE work well:
{$IFDEF EXTAI_API_DLL}KM_ExtAI_DLL in 'src\KM_ExtAI_DLL.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAI_DLLs in 'src\KM_ExtAI_DLLs.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAI_SharedTypes in 'src\KM_ExtAI_SharedTypes.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAI_SharedInterfaces in 'src\KM_ExtAI_SharedInterfaces.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAIActions in 'src\KM_ExtAIActions.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAIMaster in 'src\KM_ExtAIMaster.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAIStates in 'src\KM_ExtAIStates.pas',{$ENDIF}
{$IFDEF EXTAI_API_DLL}KM_ExtAIUtils in 'src\KM_ExtAIUtils.pas',{$ENDIF}