Edgewall Software
Modify

Opened 19 years ago

Closed 18 years ago

#3077 closed enhancement (wontfix)

load macro is slow

Reported by: toru.wata@… Owned by: Jonas Borgström
Priority: normal Milestone:
Component: wiki system Version: 0.9.5
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

If there are many macros in wiki-macros dir, then performance to render wiki pages will be getting slower.

I got perf data, then I found imp.load_source would be a bottle neck.

imp.load_source is called in UserMacroProvider defined in trac/wiki/macros.py.

   def _load_macro(self, name):
        for path in (self.env_macros, self.site_macros):
            macro_file = os.path.join(path, name + '.py')
            if os.path.isfile(macro_file):
                return imp.load_source(name, macro_file)
        raise TracError, 'Macro %s not found' % name

And more worse, above codes are called every "wiki_to_html". So if some macro uses wiki_to_html, same macro will be loaded so many times, and performance getting worse.

To solve this problem, it is necessary to check whether macro is loaded

or not.

For example if you add following codes at begining of _load_macro, then performance to render wikipage getting better even if there are so many macros.

        from sys import modules
        if modules.has_key(name):
            return modules[name]

But in above codes, there are trade-off. You cannot update macros without restarting on tracd, mod_python environment.

But I'd like you consider performance enhancement for loading macros.

Attachments (0)

Change History (3)

comment:1 by Alec Thomas, 19 years ago

A better idea might be to store the mtime of the macro and reload it if changed.

comment:2 by anonymous, 19 years ago

checking mtime requires IO for each execution. And IO is slow, generally.

I think it is better to check mtime only when "timed out". i.e. if it is loaded within recent "60 sec" then it should use loaded module. otherwise, it checks mtime and mtime is newer, then it should reload. (60 sec is a configuration parameter)

comment:3 by Christian Boos, 18 years ago

Resolution: wontfix
Status: newclosed

Well, UserMacroProvider is now dead, so there's no point in this ticket anymore.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.