Sublime Forum

Speeding up Default/settings.py

#1

I was looking into why my editor is soo slow when tying in a large file. Using the profile events command I found this:

on_modified:
PackageResourceViewer.package_resource_viewer: 3.205s total, mean: 0.004s, max: 0.066s
g4.G4: 1.631s total, mean: 0.002s, max: 0.097s
Default.settings: 7.163s total, mean: 0.010s, max: 0.061s

The method looks really simple but it takes a max of 6ms to execute. Is this because calling view.settings() is expensive to construct or is this because any event listener has a high startup cost?

1 Like

#2

The view.settings() creates a Sublime.Settings object on the first call, which might cost a little more time. As a new view is passed to the EventListener on each event, the object is created and destroyed each time. It might depend on the garbage collector or optimizations of python whether it really is or not.

Settings module takes 3ms in the mean on my box. and 13ms at max.

I turned the EventListener into a ViewEventListener with the max/mean dropping to 0ms.

EDIT: Unfortunately the ViewEventListener does not support on_pre_close()

0 Likes

#3

It would appear I should rewrite the listener, thanks for letting me know @ismell.

0 Likes