While it’s possible that DX12 could offer some enhancements for your machine, using DirectX 11 should allow the software to run much more reliably.
In nearly every post, players are advised to disable DirectX 12 to fix the problem. Forum posts and error reports about the issue litter the Star Wars Battlefront subreddit and EA Answers support forum.
Many of them reported that crashes occurred between matches, while others reported getting stuck even while navigating menus. There have been numerous reports from players whose games stalled and then eventually crashed while optimizing shaders.
You can usually prevent Star Wars Battlefront 2 from getting stuck or crashing while optimizing shaders by disabling DirectX 12. When this happens, the software will stall, often until the game crashes. Sometimes Star Wars Battlefront 2 will get stuck while optimizing shaders.