From cc1abb8c6bc45fbc576e424a76895745bb4c17ef 2019-11-13 18:42:11 From: Matthias Bussonnier Date: 2019-11-13 18:42:11 Subject: [PATCH] Merge pull request #11933 from gerrit8143/master static message instead of function call to prevent shell slowdown --- diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index eb49e67..0dda428 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -380,6 +380,16 @@ class TerminalInteractiveShell(InteractiveShell): def get_message(): return PygmentsTokens(self.prompts.in_prompt_tokens()) + if self.editing_mode == 'emacs': + # with emacs mode the prompt is (usually) static, so we call only + # the function once. With VI mode it can toggle between [ins] and + # [nor] so we can't precompute. + # here I'm going to favor the default keybinding which almost + # everybody uses to decrease CPU usage. + # if we have issues with users with custom Prompts we can see how to + # work around this. + get_message = get_message() + return { 'complete_in_thread': False, 'lexer':IPythonPTLexer(), diff --git a/docs/source/whatsnew/pr/prompt-update-modifications.rst b/docs/source/whatsnew/pr/prompt-update-modifications.rst new file mode 100644 index 0000000..77d557b --- /dev/null +++ b/docs/source/whatsnew/pr/prompt-update-modifications.rst @@ -0,0 +1,14 @@ +Prompt Rendering Performance improvements +========================================= + +Pull Request :ghpull:`11933` introduced an optimisation in the prompt rendering +logic that should decrease the resource usage of IPython when using the +_default_ configuration but could potentially introduce a regression of +functionalities if you are using a custom prompt. + +We know assume if you haven't changed the default keybindings that the prompt +**will not change** during the duration of your input – which is for example +not true when using vi insert mode that switches between `[ins]` and `[nor]` +for the current mode. + +If you are experiencing any issue let us know.