evertiro / historical-redux2

A simple, easily extendable options framework for WordPress based on NHP Theme Options Framework.
http://reduxframework.com
Other
105 stars 43 forks source link

Serious memory usage problems #90

Closed DanielBakovic closed 11 years ago

DanielBakovic commented 11 years ago

Hi, I really like your framework and I was about to use it for my themes but then I saw that each time when WordPress loads all the arrays are initialized and populated with data that are only needed on the backend (section title, sub_desc, desc, options, std). That increases the memory usage and it can slow down sites.

For example these arrays are populated but not really needed on the frontend: $args, $sections and $tabs.

Could you please optimize the framework and load only data that are really needed.

Best regards, Daniel

denis0706 commented 11 years ago

Hi. I think we shouldn't load framework at frontend at all. But with current redux version we need redux get() method to get option value, because this is the only way to get new fields with std values.

DanielBakovic commented 11 years ago

Hi, Maybe this could be solved when we check the theme version on init. For example when the theme version number isn't available in the database then the default settings should be loaded and added to the database. If there is already a older version in the database then an update function should be called to add new sections with default values. Then on the end of the update / install function there should be an action where we (developer) can hook into. For example do_action('Redux_after_setup') or something like that.

Best regards. Daniel

evertiro commented 11 years ago

You're right that the framework shouldn't be loaded in the frontend... There's gotta be a simpler way to do it though.

DanielBakovic commented 11 years ago

Thx for the understanding :)

denis0706 commented 11 years ago

Maybe just compare options from database with 'sections' array.

            $fields = array();

            foreach ( $this->sections as $section )
                foreach ( $section['fields'] as $field )
                    $fields[$field['id']] = 1;

            $diff = array_diff_key ($fields, $this->options);
            if ( !empty( $diff ) )
              // update database
DanielBakovic commented 11 years ago

Hi, when we can expect this fix?

evertiro commented 11 years ago

I'm still testing options, anyone who has a suggestion is more than welcome to bring it up, or even build it themselves and submit a pull request!

asheborocreative commented 11 years ago

If all you're trying to do is prevent loading it on the front end, just write an if statement around your require in the functions.php file that says:

if ( is_admin() ){ //require the page }

It won't even try to load it anywhere but in the admin area. Your visitors could load every front end page without having the options framework try to load. Your stored options values would still be retrievable through the get_options function in WordPress.

denis0706 commented 11 years ago

asheborocreative, agree with you, but your solution doens't work with current version of redux. Currently default options set to db only once - while there is no redux options at db. So new options added after first redux options setting to db could be retrieved only with get()

So we need to rewrite some logic of framework. Now i don't think that we shouldn't load framework at front-end at all, but use some framework function to check if there are some new options at opitons.php, no matter where we - at the admin screen or at the front-end.

evertiro commented 11 years ago

I'm still researching this, but haven't found a safe simple way of doing this without completely rewriting the framework. Any suggestions would be welcome...

DanielBakovic commented 11 years ago

I've checked the code and I don't see other really elegant solution, too. It's the base design problem but maybe this could work:

Backend

  1. Load framework files only on the backend (is_admin): 1.1 setup_framework_options 1.2 Redux_Options class 1.3. maybe some other functions
  2. On admin page check if default settings are already in the database. 2.1 If not, store all default options into the db. 2.2 If there are already options available then add only options that are not in the db yet.

Frontend

  1. On theme init, load options from the db into a global var: global $options; $options = get_option('opt_name')
  2. Add a new function to theme-options.php to retrieve options from the options array like the "get" function from Redux_Options class. For example: redux_get_option( option_name )

That will reduce the memory usage immensely.

tridungpham commented 11 years ago

how about :

dovy commented 11 years ago

@DanielBakovic @denis0706 @asheborocreative @tridungpham

With 3.0 I have reduced this dramatically. In the past, you were right. Things got loaded like mad. Let me give you an example:

I had a demo theme with 80 different options. I looked at the DB calls going on at each page load, 555. INSANE!

I then optimised 3.0 a ton and I reduced that down to 30 on the options panel and even less on the front-end.

How's that? I think you'll be SUPER please.

Give 3.0 a try next week. I've optimised everything as far as it can go.