# Performance Audit

## Audit Session - 2026-05-29 11:38:13 +03:00

## Browser Load Measurements

Measured in the in-app browser as admin after login, before the local SQLite database was reset by the test configuration.

| Page | Route | Approx Load Time |
|---|---|---:|
| Dashboard | `/admin` | 1981 ms |
| Conversations | `/admin/conversations` | 2985 ms |
| Waiting List | `/admin/conversations?tableFilters[status][value]=pending` | 2022 ms |
| Contacts | `/admin/contacts` | 2195 ms |
| Assignment Log | `/admin/assignments` | 2088 ms |
| Team | `/admin/teams` | 2041 ms |
| Reports / Webhook Events | `/admin/webhook-events` | 2077 ms |
| Permissions / Users | `/admin/users` | 3339 ms |
| Settings / Users | `/admin/users` | 1903 ms on repeat load |

No browser console errors were observed during these page loads.

## Performance Findings

| Performance Area | Finding | Evidence/File/API | Impact | Recommended Fix |
|---|---|---|---|---|
| Full page reloads | Dashboard sidebar uses hard navigation. | `resources/views/filament/pages/chat-workspace.blade.php`, `selectView()`, `window.location.href` | Every screen switch reloads full HTML, CSS, JS, Livewire, auth/session, and table data. | Stabilize shared navigation first; then consider Livewire/SPA-style navigation. |
| Navigation shell | Filament sidebar/topbar are hidden globally. | `public/css/chat-workspace.css` hides `.fi-topbar` and `.fi-sidebar` | Users cannot navigate resource pages easily; they must use browser/back/direct URL. | Scope hiding rules only to dashboard chat workspace. |
| CSS payload/conflict | AdminPanelProvider loads `crm-theme.css`, `chat-workspace.css`, and `unified-theme.css` for all pages. | `app/Providers/Filament/AdminPanelProvider.php` | Resource pages load chat-specific CSS and conflicting Filament styling rules. | Load chat CSS only on dashboard, general theme only globally. |
| Livewire table polling | Conversation table polls every 3 seconds. | `ConversationResource::table()->poll('3s')` | Repeated server requests while user is on conversations page. | Poll only if necessary or replace with targeted real-time update later. |
| Database notification polling | Filament panel polls notifications every 5 seconds. | `AdminPanelProvider::databaseNotificationsPolling('5s')` | Background requests on admin pages. | Increase interval or enable only where notifications are needed. |
| Dashboard polling | Workspace fetches `/api/workspace/data` every 15 seconds. | `loadWorkspaceData()` + `setInterval(loadWorkspaceData, 15000)` | Re-renders dashboard and reloads active messages repeatedly. | Later replace with event-driven updates; in Phase 2 keep but reduce redundant render work. |
| Repeated active message loading | Every workspace poll reloads active conversation messages. | `loadWorkspaceData()` calls `loadMessages(activeChatId, true)` | Extra API and render work during chat. | Only load messages when unread/last message changes. |
| Dashboard render strategy | `renderAll()` rewrites multiple panels on every data refresh. | `renderAll()` in chat workspace view | Can cause unnecessary DOM churn. | Split rendering by changed state. |
| Role/permission requests | Role data is embedded in `/api/workspace/data`; Filament pages still run their own auth/resource checks. | API + Filament resources | Normal, but duplicated logic increases complexity. | Centralize role rules and cache simple role/team lookups per request. |
| Large page tables | Filament tables load server-side with Livewire forms/dialogs. | Browser DOM showed many forms/dialogs on resource pages | More DOM and Livewire payload than needed for simple screens. | Keep Filament for admin pages or build custom compact screens later. |
| Missing test isolation | Test run reset local SQLite database. | `phpunit.xml` comments out test DB settings | Huge development risk and slows safe verification. | Set testing DB to `:memory:` or separate file immediately. |

## Slow Navigation Root Causes

1. Full page reloads from dashboard sidebar.
2. Global CSS and JS assets loaded across all admin pages.
3. Filament/Livewire resource pages are server-rendered and include table/form/dialog payload.
4. Polling exists in multiple layers: dashboard workspace, conversation table, database notifications.
5. Resource pages lose their navigation shell, making navigation feel slower and broken even when pages technically load.

## Items Not Optimized in Phase 1

No optimization code was applied in this phase. Recommended fixes are documented for Phase 2.

## Immediate Safety Recommendation

Before any more test runs:

```xml
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
```

or use a separate testing SQLite file. Do not run `artisan test` against the local development database.

## Phase 2 Update - 2026-05-29 12:09:31 +03:00

| Performance Area | Finding | Evidence/File/API | Impact | Recommended Fix |
|---|---|---|---|---|
| Navigation CSS | Chat workspace CSS is now scoped to pages containing `.app` and loaded only on `/admin`. | `public/css/chat-workspace.css`, `AdminPanelProvider.php` | Filament sidebar/topbar are no longer hidden globally. | Keep chat-only CSS out of resource pages. |
| Misleading full reloads | Dashboard custom sidebar still uses `window.location.href`, but routes now point to correct screens. | `chat-workspace.blade.php` | Navigation is clearer, but not optimized as SPA. | Phase 3 can reduce reloads after workflow is stable. |
| Placeholder pages | Reports/Permissions/Settings/Waiting List are lightweight pages. | New Filament pages/views | Removes costly/confusing wrong resource loads. | Replace placeholders with scoped data later. |
| Polling overlap | Dashboard workspace polling, conversation table polling, and Filament notification polling still exist. | `chat-workspace.blade.php`, `ConversationResource.php`, `AdminPanelProvider.php` | Can still affect perceived speed. | Phase 3 should rationalize polling and add lazy loading/pagination where needed. |

