telescope
telescope copied to clipboard
Telescope memory usage grows
Telescope Version
5.7
Laravel Version
12.14.1
PHP Version
8.4
Database Driver & Version
No response
Description
When running a command that inserts or updates a massive number of rows using DB::updateOrInsert, Laravel Telescope causes memory usage to explode beyond 1GB. Without Telescope, memory stays stable (~20MB). With Telescope enabled, memory keeps growing until the process eventually crashes.
Is this the intended behavior of Telescope? It’s quite tricky — I spent several hours debugging before realizing that it was Telescope consuming all the memory.
If this behavior is intentional, maybe a warning could be added to the official Laravel documentation? It’s not uncommon to handle large amounts of data, even during development...
Thanks again for this great package!
Steps To Reproduce
Add this command and run it with php artisan test:eloquent-memory
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class TestEloquentMemory extends Command
{
protected $signature = 'test:eloquent-memory';
protected $description = 'Test memory usage of updateOrInsert over 1 million rows';
public function handle()
{
$this->info("Creating table if not exists...");
DB::statement("
CREATE TABLE IF NOT EXISTS test_memory (
id BIGINT PRIMARY KEY,
updated_at TIMESTAMP NULL
)
");
$this->info("Starting inserts...");
for ($i = 1; $i <= 1_000_000; $i++) {
DB::table('test_memory')->updateOrInsert(
['id' => $i],
['updated_at' => now()]
);
if ($i % 1000 === 0) {
$memory = round(memory_get_usage() / 1024 / 1024, 2);
$peak = round(memory_get_peak_usage() / 1024 / 1024, 2);
$this->line("{$i} rows - Memory: {$memory} MB | Peak: {$peak} MB");
}
}
$this->info("Done.");
}
}
Thank you for reporting this issue!
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Thank you!
In your case you have to tell Telescope to persists records manually like that
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Laravel\Telescope\Contracts\EntriesRepository;
use Laravel\Telescope\Telescope;
class TestEloquentMemory extends Command
{
protected $signature = 'test:eloquent-memory';
protected $description = 'Test memory usage of updateOrInsert over 1 million rows';
public function handle()
{
$this->info("Creating table if not exists...");
DB::statement("
CREATE TABLE IF NOT EXISTS test_memory (
id BIGINT PRIMARY KEY,
updated_at TIMESTAMP NULL
)
");
$this->info("Starting inserts...");
for ($i = 1; $i <= 1_000_000; $i++) {
DB::table('test_memory')->updateOrInsert(
['id' => $i],
['updated_at' => now()]
);
if ($i % 1000 === 0) {
$memory = round(memory_get_usage() / 1024 / 1024, 2);
$peak = round(memory_get_peak_usage() / 1024 / 1024, 2);
$this->line("{$i} rows - Memory: {$memory} MB | Peak: {$peak} MB");
Telescope::store(app(EntriesRepository::class)); // <- tell telescope to persists records
}
}
$this->info("Done.");
}
}
Telescope queue all records in an array before persisting them. You can check \Laravel\Telescope\Telescope::store and \Laravel\Telescope\ListensForStorageOpportunities.
Alternatively for heavy operations when you might not want everything to be logged i'd suggest wrapping DB statements with:
Telescope::withoutRecording(function() {
// your code
});
“I’d like to work on this issue. Please assign it to me
I think this has been solved in telescope version 5.10,because I run it and it works well!