Тёмный
No video :(

Speed Test: Laravel CSV Export/Import Large Files in 3 Ways 

Laravel Daily
Подписаться 142 тыс.
Просмотров 33 тыс.
50% 1

There are various tools to work with Excel and CSV files import/export. I've tested 3 of them for request duration and memory usage, let's see how they performed.
Repository: github.com/LaravelDaily/Larav...
Laravel Excel package: laravel-excel.com/
Spatie Simple Excel package: github.com/spatie/simple-excel
- - - - -
Support the channel by checking out my products:
- My Laravel courses membership: laraveldaily.teachable.com/p/...
- Laravel QuickAdminPanel: bit.ly/quickadminpanel
- Livewire Kit Components: livewirekit.com
- - - - -
Other places to follow:
- My weekly Laravel newsletter: bit.ly/laravel-newsletter
- My personal Twitter: / povilaskorop

Опубликовано:

 

4 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 51   
@LaravelDaily
@LaravelDaily 2 года назад
As a few people mentioned, there's also fast-excel package. Here are the results for that, based on Pull Request by Hendra Susanto (thanks!): I find that with the right tweak, Fast Excel is the best in terms of memory usage in exporting although it can be slower than No packages or Spatie Excel. In my local test: - No packages: 2741 ms, 12 MB memory usage - Spatie: 2873 ms, 58 MB memory usage - Fast Excel: 4096 ms, 8 MB memory usage For importing it's kinda in the middle between No packages and Spatie method in terms of duration and memory usage. - No packages: 289 ms, 110 MB memory usage - Spatie: 927 ms, 54 MB memory usage - Fast Excel: 881 ms, 88 MB memory usage Pull Request: github.com/LaravelDaily/Laravel-Excel-Export-Import-Demo/pull/1
@OsaMaHasan-hawkiq
@OsaMaHasan-hawkiq 2 года назад
I always learn something new from you, but debug packages you used are life saver for me 😍
@JoffreyCarle
@JoffreyCarle 2 года назад
Hello there! Thanks for your video, instructive as always. I had this particular issue recently with a project for a client. My client needs to export a bunch of users sometimes like 10-30k users to CSV with some data transformation (to make the data in rows more user friendly). At first sight, Laravel Excel seemed to be a great choice because of his "plug-and-play" aspect. But in the end, we chose to remove it progressively as it was just causing errors in production. The documentation sometimes is a bit tricky, things does not work as expected or explained. As you mentioned, many people complained about this performance issue and ask for the use of Eloquent cursor for example to avoid this memory overload or request time out. On our side, we chose to request our database through Eloquent and stream download the file to the user which is way better than what we had with LE. I may do as you did in this video to choose future packages instead of just referring to Github stars. Thanks for the daily videos, I learn something new everyday. BTW, learned even more from your paid courses. Keep going! P.S: You said recently that you might refresh older courses for the v9. I'm really eager to see it.
@bboydarknesz
@bboydarknesz 2 года назад
wow what a great comparisons! thank you very much have no idea if there are many ways to export/import excel csv files. times to optimization!
@mouhamaddiop1144
@mouhamaddiop1144 2 года назад
Cette vidéo est particulièrement utile. Merci beaucoup.
@lucadifazio2735
@lucadifazio2735 2 года назад
This is incredible! I would have wanted to know this a year ago
@mateussantana4418
@mateussantana4418 2 года назад
Great and very interesting content! Thanks for sharing!
@ayenewyihune
@ayenewyihune Год назад
This is really helpful, I was in trouble with Laravel excel.
@aribiali3574
@aribiali3574 2 года назад
Good morning !and thnx for the video
@Vikaskumar-ur5di
@Vikaskumar-ur5di Год назад
Hi thank for sharing amazing video, i will try to implement this concept in my project
@vintopin
@vintopin 2 года назад
For low ram usage set chunkSize() and batchSize() in your laravel excel import class
@eyadbereh
@eyadbereh 2 года назад
In my humble opinion, your measurements are very close to reality Logically, the handwritten code of export using arrays is the most optimized in terms of performance and memory, because: 1-) In terms of performance, you're using the method toArray() which converts the collection into an array of associative arrays, so you're cutting off the effort to transform the collection into an array, and also you're cutting off the effort to transform every item of the array from an instance of Illuminate\Database\Eloquent\Model into an associative array, this happens only one time before the actual loop starts 2-) In terms of memory, you're just getting every entry and throwing it directly into the stream which points to csv file, nothing needs to be keeped in the memory. Plus that you're not sending the exported file directly from the stream to the browser, you're sending the file. This explains why not much memory is consumed.
@JouvaMoufette
@JouvaMoufette 2 года назад
Also, for performance, I highly recommend that, if you are certain that values in your array will never be null, to use isset($arrayName[$keyName]) over array_key_exists($keyName, $arrayName) as isset is much faster, but it will return false if the value of that key is null. But if you never need to worry about that, use isset
@kchqq
@kchqq 2 года назад
thanks for the explanation. did you have the chance to test values with empty()? curious what kind of time that method would make
@JouvaMoufette
@JouvaMoufette 2 года назад
@@kchqq I'm not sure if empty handles non-existing keys as well. It may throw a warning at minimum, whereas the isset is designed to simply detect if it's set and is a non null value, and won't throw execution warnings or errors if it doesn't exist
@kchqq
@kchqq 2 года назад
@@JouvaMoufette i think it throws error if non existent key when working with arrays, does not throw for collections tho, so i usually put ?? '' afterwards to be safe. Probably not the most efficient piece of code but it's short and readable
@JouvaMoufette
@JouvaMoufette 2 года назад
@@kchqq Yeah but what I'm speaking of here is that empty isn't a good replacement for isset, but isset is a pretty good replacement for array_key_exists
@Paltibenlaish
@Paltibenlaish 2 года назад
cool video
@ashay191
@ashay191 2 года назад
Laravel excel has a batch import function which reduces the memory usage by not using eloquent but direct db queries to insert ...for exports i think there is another option laracsv by usmanhalalit
@isaactoyin5234
@isaactoyin5234 Год назад
Hello please i have a big question, What is the advantages of using DOMPDF/ Maatwebsite\Excel package to export instead of just using the normal frontend javascript datatables with the export to pdf, excel etc buttons?
@arifdevcoding
@arifdevcoding 2 года назад
WTF! 😅. this proves that you shouldn't use 3rd party packages all the time, sometimes the raw is better
@AdamPerkinsOneAndOnly
@AdamPerkinsOneAndOnly 2 года назад
If you watched the whole video, it wasn't outright better. Spatie outperformed raw on imports.
@plpGTR
@plpGTR 2 года назад
@@AdamPerkinsOneAndOnly just like he said - not all the time ;-)
@stephenjason7575
@stephenjason7575 2 года назад
Good morning Please use map method instance of foreach in laravel
@kaisirahmed2645
@kaisirahmed2645 11 месяцев назад
How to export data into csv/xlsx by using chunk if I have only array of data qty 17000 rows? I didn't use any model in Laravel in this case. Could you please explain.
@user-fc2pd6ow9e
@user-fc2pd6ow9e 2 месяца назад
can we use spatie/simple-excell to download file using restAPI flow?
@manzoorahmed350
@manzoorahmed350 11 месяцев назад
I’m facing issue on import export in laravel 10 its not working could you please suggest me which package is best to sort the mateweb and raph2 is not working
@Barakael
@Barakael Год назад
When i try to export data from my database i got Call to a member function lazy() on array. How can i fix this?
@Hanna-iz6kp
@Hanna-iz6kp Год назад
Can you build a simple editor for me ? Please let me know if can help I need your help!
@lucianohanna1009
@lucianohanna1009 2 года назад
If you use fgetcsv instead of str_getcsv, maybe you don't have "high" memory usage. "$users = array_map('str_getcsv', file($request->file));" is putting all CSV to RAM
@antonmykhailovskyi447
@antonmykhailovskyi447 2 года назад
And if you add the generator logic (as I suppose Spatie package does), you will likely have even less memory usage
@lubomir93x
@lubomir93x 2 года назад
Treat it a bit like commercial..
@IvanilsonRibeiroConsultor
@IvanilsonRibeiroConsultor 2 года назад
Hello .. i have i challenge here. Need to create txt file based in Bank Manual here in Brazil. We call it CNAB Files.. each information need to be written in especific colunm. Example: Colunm 1 to 40 - Customer s Name, Colunm 41 to 50 - Customer s Code. and so. These files will be used to send information to bankline system, whats the best way to follow?. Congratulations for the Channel.
@fr33lummy
@fr33lummy 2 года назад
You forget fastexcel! For large data it's in my opinion the best
@sysusp
@sysusp 2 года назад
Does laravel / Excel work with Laravel 9 , please advice😀
@Alhada06
@Alhada06 2 года назад
yes it does with version 3.1
@mohamedashif7487
@mohamedashif7487 2 года назад
what about maatwebsite?
@LaravelDaily
@LaravelDaily 2 года назад
It's the same Laravel Excel
@stephenjason7575
@stephenjason7575 2 года назад
$collection = collect(['taylor', 'abigail', null])->map(function ($name) { return $name; });
@fredericauer
@fredericauer 2 года назад
And if you're usin mysql there's a faster, more efficient way to import large CSV : "LOAD DATA INFILE..."
@JohnnyBigodes
@JohnnyBigodes 2 года назад
You mean LOAD DATA LOCAL INFILE. I use it to import millions of rows every day. 👍🏻
@mohammadkhazaee9818
@mohammadkhazaee9818 2 года назад
Dammmm .... I will never use laravel excel again
@devKazuto
@devKazuto 2 года назад
I disapprove of the way you're measuring the time. The data pool for a somewhat precise time is too low. You need to run each operation multiple times and calculate the average instead of running it just once. Even local machines can have a big discrepancy in processing time for each operation. One operation can take just 240ms the first time but 1500ms the second time. That's why for benchmarks operations are executed multiple times.
@LaravelDaily
@LaravelDaily 2 года назад
That's behind the scenes but I've run those multiple times while testing BEFORE shooting the actual video
@tomiwaoluwole1818
@tomiwaoluwole1818 Год назад
I don' t think you teach newbies Because you did things that a newbie can never understand how you got it
@PunyFlash
@PunyFlash 2 года назад
Using lazy collections will probably solve memory issues
@ibrahimkhalaf4656
@ibrahimkhalaf4656 2 года назад
Yes maybe, but he used what advised in Laravel excel package right ?
@MrPatishpanj
@MrPatishpanj 2 года назад
Lazy collections = generators = spatie’s implementation
@cultureofnepal2024
@cultureofnepal2024 2 года назад
rap2hpoutre/fast-excel This package is much faster than the other 3 examples.
@tetleyk
@tetleyk 2 года назад
The only problem here is that box/spout is abandoned and Raphaël's package sits on top of that. There is a replacement for Spout called OpenSpout and there is a PR awaiting approval in fast-excel to migrate to OpenSpout v3 as it is a drop-in replacement for Spout v3. Meanwhile, OpenSpout is now at version 4 and that will require rewriting fast-excel as there are some breaking changes. Hopefully, fast-excel will remain very fast and have the additional advantage of being able to use ODS spreadsheets as well which is a major advantage for me.
Далее
Бмв сгорела , это нормально?
01:01
БАТЯ И СОСЕД😂#shorts
00:59
Просмотров 1,8 млн
Why Don't We Have A Laravel For JavaScript?
12:36
Просмотров 92 тыс.
Faster Eloquent: Avoid Accessors with Foreach
9:35
Просмотров 52 тыс.
File Upload in Laravel: Main Things You Need To Know
13:58
Laravel Queues 101: Example with Sending Emails
8:43
Laravel + Livewire todo app (and so much more)
16:41
Просмотров 37 тыс.
9 Tips for Shorter Laravel Code
10:16
Просмотров 61 тыс.
How to Bulk Insert Data With Laravel
23:42
Просмотров 10 тыс.
Laravel Eloquent: Deeper Relationships with One Query
10:37