cocur / slugify

Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.
MIT License
2.89k stars 252 forks source link

Split DefaultRules into deparate files #316

Open dkarlovi opened 2 years ago

dkarlovi commented 2 years ago

Currently, when you use the default rule provider, it loads into memory fully. This means all the rules are loaded each time, even though it's very unlikely you'll require all of them.

A better approach would be to generate one file per rule and use that to wire the rules on demand, probably using autoloading.

I've found this issue using meminfo on my app and it pointed me toward chinese rules which I don't use in my app.

Example output:

Path from 0x7fccf18bc600
+----------------------+
| Id: 0x7fccf21c24c0   |
| Type: array          |
| Size: 72 B           |
| Is root: No          |
| Children count: 6933 |
+----------------------+
         ^          
         |          
      chinese       
         |          
         |          
+--------------------+
| Id: 0x7fccf3d3e5a0 |
| Type: array        |
| Size: 72 B         |
| Is root: No        |
| Children count: 38 |
+--------------------+
         ^          
         |          
       rules        
         |          
         |          
+-------------------------------------------------------+
| Id: 0x7fccf3d3e578                                    |
| Type: object                                          |
| Class: Cocur\Slugify\RuleProvider\DefaultRuleProvider |
| Object Handle: 959                                    |
| Size: 72 B                                            |
| Is root: No                                           |
| Children count: 1                                     |
+-------------------------------------------------------+
         ^          
         |          
      provider      
         |          
         |          
+------------------------------+
| Id: 0x7fccf39ab120           |
| Type: object                 |
| Class: Cocur\Slugify\Slugify |
| Object Handle: 886           |
| Size: 72 B                   |
| Is root: No                  |
| Children count: 3            |
+------------------------------+