TinyMCE Performance

TinyMCE Performance

by Thanh Le -
Number of replies: 11

At the Open University, we have taken the TinyMCE integration code from Moodle 2.0 (with our own fixes) and deployed it as a replacement for the HTML Editor (the old HTMLArea).

However, there has been concerns over performance in cases where a Moodle page has 10 or more editors.  The performance issue can be attributed to:

1) The time to load and acquire all the TinyMCE javascript and support files; usually a one-off performance hit per browser session;

2) The time to instantiate and load an instance of editor; multiple cost for each editor instance on a page.

Has anyone experienced similiar performance issues or can offer any advice, if any, on this issue?

Thanks.

Average of ratings: -
In reply to Thanh Le

Re: TinyMCE Performance

by Mauno Korpelainen -

Hi Thanh,

Glen used TinyMCE compressor in his test integration with code

<?php
$zlib_on = ini_get('zlib.output_compression');

if (empty($zlib_on)) {
?>
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/editor/tinymce3/tiny_mce_gzip.js"></script>
<script type="text/javascript">
tinyMCE_GZ.init({
 plugins : 'style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,'+
        'searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,moodleimage,moodlelink,dragmath,inlinepopups',
 themes : 'advanced',
 languages : 'en',
 disk_cache : true,
 debug : false
});
</script>
<?php
} else {
?>
<script type="text/javascript" src="<?php echo $CFG->wwwroot ?>/lib/editor/tinymce3/tiny_mce.js"></script>
<?php
}
?>

I have not tested if it has a big infuence to performance (compressor had some bug during my testing period) but http://wiki.moxiecode.com/index.php/TinyMCE:Compressor/PHP claims that

"TinyMCE Compressor gzips all javascript files in TinyMCE to a single streamable file. This makes the overall download size 75% smaller and the number of requests will also be reduced. The overall initialization time for TinyMCE will be reduced dramaticly if you use this script."

You can downlod php compressor from http://tinymce.moxiecode.com/download.php

In reply to Thanh Le

Re: TinyMCE Performance

by Michael Penney -
We had a similar problem with Lesson back in the old old days with HTML Area - trouble is these things are mainly designed to show up once or twice per page - not 10x. At some point you have separate each instance into it's own namespace, so there is a limit to how much efficiency can be squeezed out of a stateless application. Two suggestions -

1. smile don't do that - keep the number of instances to a few per page.

2. if you need to edit multiple fields with a rich text editor, find another way (load them all into the same editor instance, for instance).

10 instances of Writely one one page would have a similar problem, and Google has spent millions (including making their own javascript engine) on thatwink.
In reply to Michael Penney

Re: TinyMCE Performance

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
1. is easy to say, but what interface would you suggest for editing a Multiple choice question with 5 answers, each of which are HTML, with HTML feedback?

Perhaps we should change formslib so that when a form contains multiple HTML areas, it acutally only loads one, which jumps around to edit whichever form-field currenly has focus?
In reply to Tim Hunt

Re: TinyMCE Performance

by Mauno Korpelainen -

Or maybe such activities that use multiple editors could use different init code and selector - you can give several init codes at the same time for tinymce - for example

http://tinymce.moxiecode.com/examples/example_15.php

http://tinymce.moxiecode.com/examples/example_13.php

http://tinymce.moxiecode.com/examples/example_12.php

http://tinymce.moxiecode.com/examples/example_04.php

In reply to Tim Hunt

Re: TinyMCE Performance

by Thanh Le -

I like this suggestion, Tim.

Although, there is still the init() time I mentioned in the earlier posting which maybe annoying.

The other issue is turning the editor on and off will leave mark-up in the text; i.e. the editor is turned on such that p-tags are added to the paragraphs.  Turn the editor off, and the text now looks like text surrounded by p-tags.... not sure how we resolve this one.

In reply to Tim Hunt

Re: TinyMCE Performance

by Michael Penney -
1. is easy to say, but what interface would you suggest for editing a Multiple choice question with 5 answers, each of which are HTML, with HTML feedback?

Could be one editor with tags. It is easy to say, not easy to do. It's easy to say "just put an editor everywhere" I guess, too - harder to handle the load all those editors put on the browser instance - going to be really hard on a limited machine (netbook, handheld, etc.).

Functionally, I like the way Salesforce handles this - click to edit field - loads edit form in one field at a time when you click to edit that field.

Show rendered html, not raw html, in the editable fields that are not currently active - raw html scares the heck out of non-technical users when it suddenly appears.
In reply to Thanh Le

Re: TinyMCE Performance

by Thanh Le -

Thanks for the feedback everyone.

Internally, I have already compressed all the files (js and CSS) and have noticed that performance has improved.  This performance fix improves the perception of speed; i.e. with 10x editors, the editors appear to load more quickly, but the actual elapsed time to initialise the editor so that it can be used is actually the same.  So the compression gives the perception of improve speed, but the actual speed improvement is not signifincant.

From my testing, the time is taken by the loading of the TinyMCE toolbar and initialising the editor.  This time is a fix time for each editor instance.

I did come to the same conlcusion yesterday that one should think carefully whether a page should have 10x editors; and if not, make the necessary changes to avoid this situation.

I guess the question remains, if there is a good reason for 10x editors, is there any potential solution to this from TinyMCE (assuming the compression is done).

In reply to Thanh Le

Re: TinyMCE Performance

by Michael Penney -
Doesn't looking at the DOM when you have multiple editors on a page give you the answer?
In reply to Thanh Le

Re: TinyMCE Performance

by Mauno Korpelainen -

If you use in init code

        theme_advanced_toolbar_location : "external",

instead of

        theme_advanced_toolbar_location : "top",

you can have 100 textareas with normal layout (not as html tags) at the same page but moodle renders toolbars only for that editor area / textarea that you click to edit

like in http://tinymce.moxiecode.com/examples/example_15.php

Another thing that could make editor much faster is to disable (=take away from init code)  plugins that you don't need

+ http://wiki.moxiecode.com/index.php/TinyMCE:Performance_tuning_TinyMCE

In reply to Mauno Korpelainen

Re: TinyMCE Performance

by Thanh Le -

The   theme_advanced_toolbar_location : "external" loks interesting.

But doesnt seem to be keyboard accessible; unless I'm missing something.

In reply to Thanh Le

Re: TinyMCE Performance

by Mauno Korpelainen -

I think lack of some keyboard shortcuts is not a problem of tinymce - it's a question of defining the shortcut keys in moodle and plugins of tinymce - and browsers http://moodle.org/mod/forum/discuss.php?d=61635

Some common shortcuts like ctrl+B, ctrl+I or ctrl+U work ok both with external and top toolbar location. It would be possible to create an "accessibility plugin" for defining any shortcuts or to use other custom editor theme than advanced theme.

In fckeditor example configurations have theme (skin) selectors, language selectors and toolbar selectors http://www.fckeditor.net/demo/toolbar?toolbar=Basic - http://www.fckeditor.net/demo/toolbar?toolbar=Default - it should be possible to write similar selectors to tinymce as well with custom buttons, lists or other selectors - inside toolbar like in http://tinymce.moxiecode.com/examples/example_16.php or outside toolbar like the toggle button (it is using just one function)

Using simple theme instead of advanced theme in activity makes tinymce a lot faster and if moodle 2.0 had even one optional editor available you could use for example the "little brother" of tinymce - punymce - if the selection code had not been cleaned away from moodle 2.0...I don't understand why we are back in one-default-editor-configuration-moodle 2.0 thoughtful