Optimize table rendering#19551
Merged
Merged
Conversation
|
Are there any details? |
Member
Author
|
Test file for ref <?php
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Support\Icons\Heroicon;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Tests\Fixtures\Models\Post;
use Filament\Tests\TestCase;
use Illuminate\Contracts\View\View;
use Illuminate\Support\MessageBag;
use Illuminate\Support\ViewErrorBag;
use Livewire\Component;
use function Filament\Tests\livewire;
uses(TestCase::class);
it('measures table render performance', function (): void {
view()->share('errors', (new ViewErrorBag)->put('default', new MessageBag));
Post::factory()->count(50)->create();
$iterations = 100;
$test = livewire(RenderPerformanceTablesComponent::class);
// Warm up — first renders do eager-loading and cache population
$test->refresh();
$test->refresh();
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$test->refresh();
}
$totalMs = (hrtime(true) - $start) / 1_000_000;
$avgMs = $totalMs / $iterations;
echo "\n";
echo 'Table render performance: ' . number_format($avgMs, 2) . ' ms per render';
echo " ({$iterations} iterations, 50 rows, 5 TextColumns, 3 row Actions)\n";
expect(true)->toBeTrue();
});
it('measures table render performance with default action groups', function (): void {
view()->share('errors', (new ViewErrorBag)->put('default', new MessageBag));
Post::factory()->count(50)->create();
$iterations = 100;
$test = livewire(ActionGroupRenderPerformanceTablesComponent::class);
$test->refresh();
$test->refresh();
$start = hrtime(true);
for ($i = 0; $i < $iterations; $i++) {
$test->refresh();
}
$totalMs = (hrtime(true) - $start) / 1_000_000;
$avgMs = $totalMs / $iterations;
echo "\n";
echo 'ActionGroup table render performance: ' . number_format($avgMs, 2) . ' ms per render';
echo " ({$iterations} iterations, 50 rows, 5 TextColumns, 1 ActionGroup with 3 inner Actions per row)\n";
expect(true)->toBeTrue();
});
class ActionGroupRenderPerformanceTablesComponent extends Component implements HasActions, HasSchemas, Tables\Contracts\HasTable
{
use InteractsWithActions;
use InteractsWithSchemas;
use Tables\Concerns\InteractsWithTable;
public function table(Table $table): Table
{
return $table
->query(Post::query())
->columns([
TextColumn::make('id'),
TextColumn::make('title'),
TextColumn::make('content'),
TextColumn::make('rating'),
TextColumn::make('is_published'),
])
->recordActions([
ActionGroup::make([
Action::make('view')->icon(Heroicon::Eye)->url(fn (Post $record): string => "/posts/{$record->id}"),
Action::make('edit')->icon(Heroicon::PencilSquare)->url(fn (Post $record): string => "/posts/{$record->id}/edit"),
Action::make('delete')->icon(Heroicon::Trash)->color('danger'),
]),
])
->paginated(false);
}
public function render(): View
{
return view('livewire.table');
}
}
class RenderPerformanceTablesComponent extends Component implements HasActions, HasSchemas, Tables\Contracts\HasTable
{
use InteractsWithActions;
use InteractsWithSchemas;
use Tables\Concerns\InteractsWithTable;
public function table(Table $table): Table
{
return $table
->query(Post::query())
->columns([
TextColumn::make('id'),
TextColumn::make('title'),
TextColumn::make('content'),
TextColumn::make('rating'),
TextColumn::make('is_published'),
])
->recordActions([
Action::make('view')->icon(Heroicon::Eye)->url(fn (Post $record): string => "/posts/{$record->id}"),
Action::make('edit')->icon(Heroicon::PencilSquare)->url(fn (Post $record): string => "/posts/{$record->id}/edit"),
Action::make('delete')->icon(Heroicon::Trash)->color('danger'),
])
->paginated(false);
}
public function render(): View
{
return view('livewire.table');
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.