Skip to content

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jul 13, 2023

Description
Paths is immutable, so we do not need to share the instance.
And config(Paths::class) is slower than new Paths().

Test Time Memory
new paths() 0.0023 0 Bytes
config(paths::class) 0.0182 0 Bytes
<?php

namespace App\Controllers;

use Config\Paths;

class Home extends BaseController
{
    public function index()
    {
        $iterator = new \CodeIgniter\Debug\Iterator();

        $iterator->add('new Paths()', static function () {
            $config = new Paths();
        });

        $iterator->add('config(Paths::class)', static function () {
            $config = config(Paths::class);
        });

        return $iterator->run(10000);
    }
}

Related #7696

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

kenjis added 3 commits July 13, 2023 16:03
`new Paths()` is faster than config(), and Paths is immutable.
@kenjis kenjis added the refactor Pull requests that refactor code label Jul 13, 2023
@kenjis kenjis mentioned this pull request Jul 13, 2023
5 tasks
@kenjis kenjis merged commit e37b134 into codeigniter4:develop Jul 16, 2023
@kenjis kenjis deleted the refactor-config-Paths branch July 16, 2023 05:52
totoprayogo1916 added a commit to totoprayogo1916/framework-CI4 that referenced this pull request Oct 13, 2025
  - explain class requirements prior to autoloader instantiation
  - clarify that Paths class does not extend BaseConfig
  - see codeigniter4#7702
totoprayogo1916 added a commit to totoprayogo1916/framework-CI4 that referenced this pull request Oct 13, 2025
  - explain class requirements prior to autoloader instantiation
  - clarify that Paths class does not extend BaseConfig
  - see codeigniter4#7702
michalsn pushed a commit that referenced this pull request Oct 14, 2025
- explain class requirements prior to autoloader instantiation
  - clarify that Paths class does not extend BaseConfig
  - see #7702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants