@@ -65,13 +65,41 @@ private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
6565 try
6666 {
6767 PassportLogger . Info ( $ "{ TAG } Starting Vuplex CanvasWebViewPrefab instantiation...") ;
68+
69+ // Apply aggressive performance optimizations for macOS
70+ try
71+ {
72+ StandaloneWebView . SetCommandLineArguments (
73+ "--disable-gpu " +
74+ "--disable-gpu-compositing " +
75+ "--disable-software-rasterizer " +
76+ "--disable-background-timer-throttling " +
77+ "--disable-renderer-backgrounding " +
78+ "--disable-features=TranslateUI " +
79+ "--no-sandbox"
80+ ) ;
81+ PassportLogger . Info ( $ "{ TAG } Applied comprehensive performance optimizations for macOS") ;
82+ }
83+ catch ( System . Exception ex )
84+ {
85+ PassportLogger . Warn ( $ "{ TAG } Could not apply performance optimizations: { ex . Message } ") ;
86+ }
87+
6888 // Create WebView prefab and parent to Canvas
6989 _webViewPrefab = CanvasWebViewPrefab . Instantiate ( ) ;
7090 PassportLogger . Info ( $ "{ TAG } CanvasWebViewPrefab created successfully") ;
71- _webViewPrefab . Native2DModeEnabled = true ; // Use Native2DMode for better performance on desktop
72-
73- // Set lower resolution for faster loading and rendering
74- _webViewPrefab . Resolution = 0.75f ; // Balanced resolution for desktop
91+
92+ // Enable Native2DMode and additional performance settings
93+ _webViewPrefab . Native2DModeEnabled = true ; // Direct native rendering - fastest on desktop
94+ _webViewPrefab . Resolution = 0.5f ; // Balanced resolution for desktop
95+
96+ // Additional 2D mode optimizations
97+ if ( _webViewPrefab . Native2DModeEnabled )
98+ {
99+ PassportLogger . Info ( $ "{ TAG } Native2DMode confirmed enabled - using direct native rendering") ;
100+ // In Native2D mode, reduce pixel density for better performance
101+ _webViewPrefab . PixelDensity = 1.0f ; // Standard density, no high-DPI overhead
102+ }
75103
76104 // Must be child of Canvas for Vuplex to work
77105 _webViewPrefab . transform . SetParent ( _canvasReference . canvas . transform , false ) ;
@@ -89,9 +117,31 @@ private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
89117
90118 PassportLogger . Info ( $ "{ TAG } Using WebView dimensions: { width } x{ height } ") ;
91119
92- // Wait for WebView initialization
120+ // Wait for WebView initialization with timing
121+ var startTime = System . DateTime . Now ;
93122 await _webViewPrefab . WaitUntilInitialized ( ) ;
94- PassportLogger . Info ( $ "{ TAG } Vuplex WebView initialization completed") ;
123+ var initTime = ( System . DateTime . Now - startTime ) . TotalSeconds ;
124+ PassportLogger . Info ( $ "{ TAG } Vuplex WebView initialization completed in { initTime : F2} s") ;
125+
126+ // Pre-load the login page for instant display
127+ try
128+ {
129+ if ( ! string . IsNullOrEmpty ( config . InitialUrl ) && config . InitialUrl != "about:blank" )
130+ {
131+ _webViewPrefab . WebView . LoadUrl ( config . InitialUrl ) ;
132+ PassportLogger . Info ( $ "{ TAG } Pre-loaded login page: { config . InitialUrl } ") ;
133+ }
134+ else
135+ {
136+ // Load minimal blank page if no URL provided (rare edge case)
137+ _webViewPrefab . WebView . LoadHtml ( "<html><body style='margin:0;padding:20px;font-family:system-ui;color:#666;text-align:center;'>Initializing...</body></html>" ) ;
138+ PassportLogger . Info ( $ "{ TAG } Loaded minimal blank page (no InitialUrl provided)") ;
139+ }
140+ }
141+ catch ( System . Exception ex )
142+ {
143+ PassportLogger . Warn ( $ "{ TAG } Could not pre-load content: { ex . Message } ") ;
144+ }
95145
96146 // Setup event handlers
97147 _webViewPrefab . WebView . LoadProgressChanged += ( sender , progressArgs ) =>
@@ -157,6 +207,19 @@ public void LoadUrl(string url)
157207 return ;
158208 }
159209
210+ // Check if the requested URL is already loaded (performance optimization)
211+ var currentUrl = _webViewPrefab . WebView . Url ;
212+ if ( currentUrl == url )
213+ {
214+ PassportLogger . Info ( $ "{ TAG } URL already loaded, showing instantly: { url } ") ;
215+ // No need to reload - just show the WebView if hidden
216+ if ( ! _webViewPrefab . Visible )
217+ {
218+ _webViewPrefab . Visible = true ;
219+ }
220+ return ;
221+ }
222+
160223 PassportLogger . Info ( $ "{ TAG } Loading URL: { url } ") ;
161224 _webViewPrefab . WebView . LoadUrl ( url ) ;
162225 }
0 commit comments