Welcome Guest, Not a member yet? Register   Sign In
Shield's autoloading performance
#1

(This post was last modified: 09-26-2023, 03:01 AM by Muzikant.)

I am starting with Shield. After successful installation (Composer and Spark) I realized, that Auth helper is autoloaded everywhere. I need it only in admin panel, nowhere else. The documentation is saying, it is autoloaded by Composer.

  1. Is it possible to load Shield only where I want it?
  2. Does autoloading in Composer have impact on performance as level 1 optimization is enabled by default?

I realized, that Shield's dependency Settings library is always sending database request for settings table, even if I am not using neither the Shield or the Settings library. This behavior is unwanted for me. (Edit: It was my mistake. It is not doing this.)

CodeIgniter 3 and less was great, because it was not loading anything "for me" until I specifically asked for it. I know, Shield is not essential part of CI, but this behavior looks like Laravel style, which is leading to bloating software, which I really do not want and I am suspicious on CI too now as Lonnie is an active member of the community. I really hope CodeIgniter is not heading this way, because why should I use Laravel style framework, if I can use Laravel directly? And why should I use Shield, if it is doing stuff "for me", which I really do not want?
Reply
#2

Indeed, auth_helper is always loaded by Composer. However, the file is small and this is not perceived as a problem.

If you really think it is a problem, please benchmark its impact and provide data.
If the autoloading load is too large to be ignored, then stopping the autoloading may be considered.
There is no way to stop it now, expect modifying Shield.

As for Settings, yes, there are indeed wasted database accesses when settings are not stored in the database.
However, when you are not using Shield, I don't think it would access the database.
Reply
#3

(This post was last modified: 09-26-2023, 03:08 AM by Muzikant.)

Thank you for your reply. I am convinced now, it is rather the conceptual question than the performance one, but I am still prefer load it by myself, not automatically.

With Settings library database request you are right. I made a mistake. No, it is not requesting database until you are using Auth helper. I am sorry.
Reply
#4

(This post was last modified: 09-29-2023, 02:30 AM by Muzikant.)

As the Shield is not final yet, it should be considered, if Auth library should be autoloaded and if Shield should requesting database, if Settings library is unused (probably not using Settings library at all).
Reply
#5

Shield uses the setting() function.
You could extends the function so that just returns the Config values.
See https://codeigniter4.github.io/CodeIgnit...ng-helpers
Reply
#6

@Muzikant See https://github.com/codeigniter4/shield/pull/872
Reply
#7

(This post was last modified: 10-03-2023, 02:55 AM by Muzikant.)

Thank you for considering it. I am just giving you a feedback. I really like CodeIgniter and I am using it for years. The loading only what is necessary is one of the key elements of it (IMHO).

In development Yii 3 have written key concepts (Yii goal and values). Do we have something like that?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB