emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* long code blocks making Org Mode very slow
@ 2015-07-14 18:15 Angus M
  2015-07-14 19:41 ` Sebastien Vauban
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Angus M @ 2015-07-14 18:15 UTC (permalink / raw)
  To: emacs-orgmode

I'm trying to run a long Python code block (~4000 lines) in org mode.  The
code is sandwiched between:
#+begin_src python
<python code block>
#+end_src

It runs fine, but org mode becomes incredibly slow - when typing text there
is about a 10 second delay before the character appears on the screen.  If I
reduce the number of lines of code in the block there is a noticeable
increase in speed.

I am not using line numbers, and the delay is not ameliorated by turning off
fontification.

If I add a semi-colon before #+begin_src, to comment it off (get rid of src
environment), then org mode returns to it's normal speed.

Do I just have to accept that long code blocks can't be entered into Org Mode?  

Any help would be appreciated.  I am running Org Mode (version 8.2.10) on
Windows 8.

Thanks

Angus M

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-14 18:15 long code blocks making Org Mode very slow Angus M
@ 2015-07-14 19:41 ` Sebastien Vauban
  2015-07-14 21:06   ` Angus M
  2015-07-14 21:44 ` Nick Dokos
  2015-07-15 12:22 ` Angus M
  2 siblings, 1 reply; 12+ messages in thread
From: Sebastien Vauban @ 2015-07-14 19:41 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Angus M <anguscmelville-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> I'm trying to run a long Python code block (~4000 lines) in org mode.  The
> code is sandwiched between:
> #+begin_src python
> <python code block>
> #+end_src
>
> It runs fine, but org mode becomes incredibly slow - when typing text there
> is about a 10 second delay before the character appears on the screen.  If I
> reduce the number of lines of code in the block there is a noticeable
> increase in speed.
>
> I am not using line numbers, and the delay is not ameliorated by turning off
> fontification.
>
> If I add a semi-colon before #+begin_src, to comment it off (get rid of src
> environment), then org mode returns to it's normal speed.

The best thing to do, now, is run the profiler:

M-x profiler-start
... type one character (which takes 10 s to be rendered)
M-x profiler-report

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-14 19:41 ` Sebastien Vauban
@ 2015-07-14 21:06   ` Angus M
  0 siblings, 0 replies; 12+ messages in thread
From: Angus M @ 2015-07-14 21:06 UTC (permalink / raw)
  To: emacs-orgmode

Sebastien Vauban <sva-news@...> writes:

> 
> Angus M <anguscmelville@...> writes:
> > I'm trying to run a long Python code block (~4000 lines) in org mode.  The
> > code is sandwiched between:
> > #+begin_src python
> > <python code block>
> > #+end_src
> >
> > It runs fine, but org mode becomes incredibly slow - when typing text there
> > is about a 10 second delay before the character appears on the screen.  If I
> > reduce the number of lines of code in the block there is a noticeable
> > increase in speed.
> >
> > I am not using line numbers, and the delay is not ameliorated by turning off
> > fontification.
> >
> > If I add a semi-colon before #+begin_src, to comment it off (get rid of src
> > environment), then org mode returns to it's normal speed.
> 
> The best thing to do, now, is run the profiler:
> 
> M-x profiler-start
> ... type one character (which takes 10 s to be rendered)
> M-x profiler-report
> 
> Best regards,
>   Seb
> 

Many thanks.

I've run the profiler, but am not quite sure what to make of the result
(fully expanded):

- ...                                                            1199  99%
 - while                                                         1194  98%
  - cond                                                         1194  98%
   - setq                                                        1194  98%
    - org-footnote-at-reference-p                                1194  98%
     - if                                                        1194  98%
      - save-excursion                                           1179  97%
       - org-footnote-in-valid-context-p                         1179  97%
        - let                                                    1179  97%
         - unwind-protect                                        1179  97%
          - progn                                                1179  97%
           - not                                                 1179  97%
            - or                                                 1179  97%
             - org-in-block-p                                    1177  97%
              - let                                              1177  97%
               - unwind-protect                                  1177  97%
                - progn                                          1177  97%
                 - catch                                         1177  97%
                  - let                                          1177  97%
                   - mapc                                        1168  96%
                    - #<lambda 0x1bd609a3>                       1168  96%
                     - let                                       1168  96%
                      - if                                       1168  96%
                       - org-between-regexps-p                   1168  96%
                        - let                                    1168  96%
                         - unwind-protect                        1168  96%
                          - progn                                1167  96%
                           - let                                 1167  96%
                            - or                                  672  55%
                             - save-excursion                     672  55%
                                outline-next-heading                478  39%
                                outline-previous-heading                193  15%
                            - save-excursion                      495  40%
                             - and                                495  40%
                              - or                                291  24%
                               - org-at-regexp-p                    1   0%
                                - catch                             1   0%
                                 - save-excursion                   1   0%
                                    let                             1   0%
                                not                               115   9%
                   - save-excursion                                 9   0%
                      outline-previous-heading                      8   0%
                      outline-next-heading                          1   0%
             - org-in-verbatim-emphasis                             2   0%
              - let                                                 2   0%
               - unwind-protect                                     2   0%
                - progn                                             2   0%
                 - and                                              2   0%
                  - org-in-regexp                                   2   0%
                   - catch                                          2   0%
                    - let                                           2   0%
                     - save-excursion                               1   0%
                      - beginning-of-line                           1   0%
                         -                                          1   0%
      - and                                                        15   1%
       - org-footnote-in-valid-context-p                           15   1%
        - let                                                      15   1%
         - unwind-protect                                          15   1%
          - progn                                                  15   1%
           - not                                                   15   1%
            - or                                                   15   1%
             - org-in-block-p                                      14   1%
              - let                                                14   1%
               - unwind-protect                                    14   1%
                - progn                                            14   1%
                 - catch                                           14   1%
                  - let                                            14   1%
                   - save-excursion                                14   1%
                      outline-previous-heading                     10   0%
                      outline-next-heading                          4   0%
             - org-in-verbatim-emphasis                             1   0%
              - let                                                 1   0%
               - unwind-protect                                     1   0%
                  progn                                             1   0%
   Automatic GC                                                     5   0%
- redisplay_internal (C function)                                  10   0%
 - jit-lock-function                                               10   0%
  - jit-lock-fontify-now                                           10   0%
   - funcall                                                       10   0%
    - #<compiled 0xf18aef>                                         10   0%
     - run-hook-with-args                                          10   0%
      - font-lock-fontify-region                                   10   0%
       - font-lock-default-fontify-region                          10   0%
        - font-lock-fontify-keywords-region                         9   0%
         - org-activate-plain-links                                 2   0%
          - let                                                     2   0%
           - if                                                     2   0%
              and                                                   2   0%
        - font-lock-unfontify-region                                1   0%
         - org-unfontify-region                                     1   0%
            let*                                                    1   0%
- command-execute                                                   2   0%
 - call-interactively                                               2   0%
  - byte-code                                                       2   0%
   - read-extended-command                                          2   0%
    - completing-read                                               2   0%
     - completing-read-default                                      2   0%
        read-from-minibuffer                                        1   0%

It seems to checking for a footnote reference.  Is this anything out of the
ordinary?  My text contains no footnotes.  Any pointers in the right
direction greatly appreciated.

Thanks

Angus M

P.s.  This problem still occurs with only the basic 'starter' org mode
.emacs init file.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-14 18:15 long code blocks making Org Mode very slow Angus M
  2015-07-14 19:41 ` Sebastien Vauban
@ 2015-07-14 21:44 ` Nick Dokos
  2015-07-14 23:39   ` Angus M
  2015-07-15 12:22 ` Angus M
  2 siblings, 1 reply; 12+ messages in thread
From: Nick Dokos @ 2015-07-14 21:44 UTC (permalink / raw)
  To: emacs-orgmode

Angus M <anguscmelville@gmail.com> writes:

> I'm trying to run a long Python code block (~4000 lines) in org mode.  The
> code is sandwiched between:
> #+begin_src python
> <python code block>
> #+end_src
>
> It runs fine, but org mode becomes incredibly slow - when typing text there
> is about a 10 second delay before the character appears on the screen.  If I
> reduce the number of lines of code in the block there is a noticeable
> increase in speed.
>

That's because a) emacs is single-threaded and b) babel blocks are
executed synchronously. emacs waits for the code block to finish
executing before going on with its business.

See e.g. the thread at

http://article.gmane.org/gmane.emacs.orgmode/83704

> I am not using line numbers, and the delay is not ameliorated by turning off
> fontification.
>
> If I add a semi-colon before #+begin_src, to comment it off (get rid of src
> environment), then org mode returns to it's normal speed.
>
> Do I just have to accept that long code blocks can't be entered into Org Mode?  
>

Now I'm confused: are you executing the code block or aren't you?

IIUC, code blocks can be of arbitrary length: but if you try to run one, you
gotta wait till it finishes. Is that what you are complaining about or
do you see something else?

> Any help would be appreciated.  I am running Org Mode (version 8.2.10) on
> Windows 8.
>

Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-14 21:44 ` Nick Dokos
@ 2015-07-14 23:39   ` Angus M
  0 siblings, 0 replies; 12+ messages in thread
From: Angus M @ 2015-07-14 23:39 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <ndokos <at> gmail.com> writes:

Many thanks for your help Nick - see comments below

> > I'm trying to run a long Python code block (~4000 lines) in org mode.  The
> > code is sandwiched between:
> > #+begin_src python
> > <python code block>
> > #+end_src
> >
> > It runs fine, but org mode becomes incredibly slow - when typing text there
> > is about a 10 second delay before the character appears on the screen.  If I
> > reduce the number of lines of code in the block there is a noticeable
> > increase in speed.
> >
> 
> That's because a) emacs is single-threaded and b) babel blocks are
> executed synchronously. emacs waits for the code block to finish
> executing before going on with its business.

Perhaps I should have been clearer: org mode is incredibly slow to respond
(to a key press or to scrolling) even before a block is executed.  It is not
an issue with waiting for a code block to finish executing.  

> > I am not using line numbers, and the delay is not ameliorated by turning off
> > fontification.
> >
> > If I add a semi-colon before #+begin_src, to comment it off (get rid of src
> > environment), then org mode returns to it's normal speed.
> >
> > Do I just have to accept that long code blocks can't be entered into Org
Mode?  
> >
> 
> Now I'm confused: are you executing the code block or aren't you?
> 
> IIUC, code blocks can be of arbitrary length: but if you try to run one, you
> gotta wait till it finishes. Is that what you are complaining about or
> do you see something else?

No, I wasn't executing the code block.  I just wanted to point out that the
org mode slow down was only when the system could see that the long code
block was present, i.e. by removing the src environment, by commenting off
the #+begin_src marker, the delay disappeared.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-14 18:15 long code blocks making Org Mode very slow Angus M
  2015-07-14 19:41 ` Sebastien Vauban
  2015-07-14 21:44 ` Nick Dokos
@ 2015-07-15 12:22 ` Angus M
  2015-07-17  1:10   ` Grant Rettke
  2 siblings, 1 reply; 12+ messages in thread
From: Angus M @ 2015-07-15 12:22 UTC (permalink / raw)
  To: emacs-orgmode

I've just discovered that the slow-response is definitely related to font
locking.  If I type M-x font-lock-mode to toggle it off then the typing lag
problem is solved.

According to the Emacs documentation:
'In Emacs 21 and later, turning on font-lock-mode automatically activates
the new Just-In-Time fontification provided by jit-lock-mode.'

It would appear, therefore, that just-in-time fontification is not taking
place in the code block with the whole code block being fontified at once -
and hence the delay.

Any help to confirm this hypothesis and how to enable just-in-time
fontification in the code block would be appreciated.

Angus M

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-15 12:22 ` Angus M
@ 2015-07-17  1:10   ` Grant Rettke
  2015-07-21 11:09     ` Angus M
  0 siblings, 1 reply; 12+ messages in thread
From: Grant Rettke @ 2015-07-17  1:10 UTC (permalink / raw)
  To: Angus M; +Cc: emacs-orgmode@gnu.org

Post a Gist of your file so I can try it out.

What is you value of `org-src-fontify-natively'?
Grant Rettke
--
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
“All creativity is an extended form of a joke.” --Kay
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson


On Wed, Jul 15, 2015 at 7:22 AM, Angus M <anguscmelville@gmail.com> wrote:
> I've just discovered that the slow-response is definitely related to font
> locking.  If I type M-x font-lock-mode to toggle it off then the typing lag
> problem is solved.
>
> According to the Emacs documentation:
> 'In Emacs 21 and later, turning on font-lock-mode automatically activates
> the new Just-In-Time fontification provided by jit-lock-mode.'
>
> It would appear, therefore, that just-in-time fontification is not taking
> place in the code block with the whole code block being fontified at once -
> and hence the delay.
>
> Any help to confirm this hypothesis and how to enable just-in-time
> fontification in the code block would be appreciated.
>
> Angus M
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-17  1:10   ` Grant Rettke
@ 2015-07-21 11:09     ` Angus M
  2015-07-22  1:20       ` Grant Rettke
  0 siblings, 1 reply; 12+ messages in thread
From: Angus M @ 2015-07-21 11:09 UTC (permalink / raw)
  To: emacs-orgmode

> Post a Gist of your file so I can try it out.
> 
> What is you value of `org-src-fontify-natively'?

> Grant Rettke
> --
> gcr <at> wisdomandwonder.com | http://www.wisdomandwonder.com/
> “Wisdom begins in wonder.” --Socrates
> “All creativity is an extended form of a joke.” --Kay
> ((λ (x) (x x)) (λ (x) (x x)))
> “Life has become immeasurably better since I have been forced to stop
> taking it seriously.” --Thompson
> 
> On Wed, Jul 15, 2015 at 7:22 AM, Angus M <anguscmelville <at> gmail.com>
wrote:
> > I've just discovered that the slow-response is definitely related to font
> > locking.  If I type M-x font-lock-mode to toggle it off then the typing lag
> > problem is solved.
> >
> > According to the Emacs documentation:
> > 'In Emacs 21 and later, turning on font-lock-mode automatically activates
> > the new Just-In-Time fontification provided by jit-lock-mode.'
> >
> > It would appear, therefore, that just-in-time fontification is not taking
> > place in the code block with the whole code block being fontified at once -
> > and hence the delay.
> >
> > Any help to confirm this hypothesis and how to enable just-in-time
> > fontification in the code block would be appreciated.
> >
> > Angus M

Thanks for your help.

Any script of a significant length sandwiched as a snippet in org mode between:
#+begin_src python
[code]
#+end_src

causes the slow-down.

For example the (arbitrarily chosen) file argparse.py found at
https://code.google.com/p/argparse
/downloads/detail?name=argparse-1.2.1.tar.gz&can=2&q=
is 2400 lines long, and causes a lag of about 1 or 2 seconds for a character
to appear on the screen after a key press.

The issue is not to do with running the script, (which I haven't tried with
this example).

My value for org-src-fontify-natively:
(setq org-src-fontify-natively t)

This issue is of less importance to me now as I think it probably makes
sense to run any script of significant length as a stand-alone 'python mode'
file, which I'm now doing - rather than as a snippet in 'org mode'. 
Therefore unless you're curious to solve this problem for its own sake,
please don't invest any significant time on trying to sort it out on my
behalf.  Thanks!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-21 11:09     ` Angus M
@ 2015-07-22  1:20       ` Grant Rettke
  2015-07-22 10:09         ` Angus M
  0 siblings, 1 reply; 12+ messages in thread
From: Grant Rettke @ 2015-07-22  1:20 UTC (permalink / raw)
  To: Angus M; +Cc: emacs-orgmode@gnu.org

When I have the cursor inside of the code block for the code, moving
up or done one line or one page takes 2-3 seconds.
Grant Rettke
--
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
“All creativity is an extended form of a joke.” --Kay
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson


On Tue, Jul 21, 2015 at 6:09 AM, Angus M <anguscmelville@gmail.com> wrote:
>> Post a Gist of your file so I can try it out.
>>
>> What is you value of `org-src-fontify-natively'?
>
>> Grant Rettke
>> --
>> gcr <at> wisdomandwonder.com | http://www.wisdomandwonder.com/
>> “Wisdom begins in wonder.” --Socrates
>> “All creativity is an extended form of a joke.” --Kay
>> ((λ (x) (x x)) (λ (x) (x x)))
>> “Life has become immeasurably better since I have been forced to stop
>> taking it seriously.” --Thompson
>>
>> On Wed, Jul 15, 2015 at 7:22 AM, Angus M <anguscmelville <at> gmail.com>
> wrote:
>> > I've just discovered that the slow-response is definitely related to font
>> > locking.  If I type M-x font-lock-mode to toggle it off then the typing lag
>> > problem is solved.
>> >
>> > According to the Emacs documentation:
>> > 'In Emacs 21 and later, turning on font-lock-mode automatically activates
>> > the new Just-In-Time fontification provided by jit-lock-mode.'
>> >
>> > It would appear, therefore, that just-in-time fontification is not taking
>> > place in the code block with the whole code block being fontified at once -
>> > and hence the delay.
>> >
>> > Any help to confirm this hypothesis and how to enable just-in-time
>> > fontification in the code block would be appreciated.
>> >
>> > Angus M
>
> Thanks for your help.
>
> Any script of a significant length sandwiched as a snippet in org mode between:
> #+begin_src python
> [code]
> #+end_src
>
> causes the slow-down.
>
> For example the (arbitrarily chosen) file argparse.py found at
> https://code.google.com/p/argparse
> /downloads/detail?name=argparse-1.2.1.tar.gz&can=2&q=
> is 2400 lines long, and causes a lag of about 1 or 2 seconds for a character
> to appear on the screen after a key press.
>
> The issue is not to do with running the script, (which I haven't tried with
> this example).
>
> My value for org-src-fontify-natively:
> (setq org-src-fontify-natively t)
>
> This issue is of less importance to me now as I think it probably makes
> sense to run any script of significant length as a stand-alone 'python mode'
> file, which I'm now doing - rather than as a snippet in 'org mode'.
> Therefore unless you're curious to solve this problem for its own sake,
> please don't invest any significant time on trying to sort it out on my
> behalf.  Thanks!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-22  1:20       ` Grant Rettke
@ 2015-07-22 10:09         ` Angus M
  2015-07-22 12:41           ` Nick Dokos
  0 siblings, 1 reply; 12+ messages in thread
From: Angus M @ 2015-07-22 10:09 UTC (permalink / raw)
  To: emacs-orgmode

> When I have the cursor inside of the code block for the code, moving
> up or done one line or one page takes 2-3 seconds.
> Grant Rettke
> --

Thanks for confirming that you also experience the slow-down.

I think that the only way to remedy this is to modify the
'org-src-font-lock-fontify-block' function in org-src.el to allow
just-in-time fontification, (rather than the current complete
re-fontification of the whole code block upon any changes).

Does anyone know of a list of 'nice-to-have' features that this could be
added to to allow possible development sometime in the future? 
(Unfortunately I am new to eLisp, and so making such changes is currently
beyond my capabilities.)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-22 10:09         ` Angus M
@ 2015-07-22 12:41           ` Nick Dokos
  2015-07-22 23:09             ` Grant Rettke
  0 siblings, 1 reply; 12+ messages in thread
From: Nick Dokos @ 2015-07-22 12:41 UTC (permalink / raw)
  To: emacs-orgmode

Angus M <anguscmelville@gmail.com> writes:

>> When I have the cursor inside of the code block for the code, moving
>> up or done one line or one page takes 2-3 seconds.
>> Grant Rettke
>> --
>
> Thanks for confirming that you also experience the slow-down.
>
> I think that the only way to remedy this is to modify the
> 'org-src-font-lock-fontify-block' function in org-src.el to allow
> just-in-time fontification, (rather than the current complete
> re-fontification of the whole code block upon any changes).
>

I'm not convinced that this is the reason. I tried with a simple file
(a headline, some text, a source code block with 7K lines of python -
the decimal.py file from the standard python library - and some more
text).

I set org-src-fontify-natively to nil (through a local variable in
the file). Adding text after the code block was OK but adding text
before the code block was very slow. If fontification were the problem,
I'd expect both to be fast.

I did a profile with elp and it seems to me that the problem is footnote
detection:

--8<---------------cut here---------------start------------->8---
org-activate-footnote-links                                   7           13.397064245  1.9138663207
org-footnote-next-reference-or-definition                     7           13.396982566  1.9138546524
org-footnote-in-valid-context-p                               378         13.384084804  0.0354076317
org-in-block-p                                                322         13.146482877  0.0408275865
org-between-regexps-p                                         2576        12.544080215  0.0048695963
org-footnote-at-reference-p                                   189         6.7601071689  0.0357677627
org-footnote-at-definition-p                                  189         6.6263815400  0.0350602197
org-element--parse-to                                         15          0.41858634    0.027905756
org-element--cache-sync                                       18          0.3965463360  0.0220303520
org-fontify-meta-lines-and-blocks                             14          0.3946110120  0.0281865008
org-fontify-meta-lines-and-blocks-1                           14          0.3944775729  0.0281769695
org-element--current-element                                  7           0.3642047120  0.0520292445
...
--8<---------------cut here---------------end--------------->8---

I didn't check how org-between-regexps-p and org-footnote-at-*-p are
related, but those three seem to account for the lion's share of the
time.

BTW, org-src-font-lock-fontify-block calls font-lock-fontify-buffer
which is not supposed to be called from lisp programs: the doc string
suggests using font-lock-ensure or font-lock-flush. I tried the first
but it did not make any difference in the speed. But I guess it should
be changed.

-- 
Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: long code blocks making Org Mode very slow
  2015-07-22 12:41           ` Nick Dokos
@ 2015-07-22 23:09             ` Grant Rettke
  0 siblings, 0 replies; 12+ messages in thread
From: Grant Rettke @ 2015-07-22 23:09 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode@gnu.org

I will play around with it. I didn't try to do a ECM.

Playing around with it tonight starting with

open /Applications/Emacs.app --new --args -Q

So using 8.2.10.

Sometimes I can get a slow down when calling `next-line' repeatedly.

I will play around with it and report if I get something reproducible
and an ECM.
Grant Rettke
--
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
“All creativity is an extended form of a joke.” --Kay
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson


On Wed, Jul 22, 2015 at 7:41 AM, Nick Dokos <ndokos@gmail.com> wrote:
> Angus M <anguscmelville@gmail.com> writes:
>
>>> When I have the cursor inside of the code block for the code, moving
>>> up or done one line or one page takes 2-3 seconds.
>>> Grant Rettke
>>> --
>>
>> Thanks for confirming that you also experience the slow-down.
>>
>> I think that the only way to remedy this is to modify the
>> 'org-src-font-lock-fontify-block' function in org-src.el to allow
>> just-in-time fontification, (rather than the current complete
>> re-fontification of the whole code block upon any changes).
>>
>
> I'm not convinced that this is the reason. I tried with a simple file
> (a headline, some text, a source code block with 7K lines of python -
> the decimal.py file from the standard python library - and some more
> text).
>
> I set org-src-fontify-natively to nil (through a local variable in
> the file). Adding text after the code block was OK but adding text
> before the code block was very slow. If fontification were the problem,
> I'd expect both to be fast.
>
> I did a profile with elp and it seems to me that the problem is footnote
> detection:
>
> --8<---------------cut here---------------start------------->8---
> org-activate-footnote-links                                   7           13.397064245  1.9138663207
> org-footnote-next-reference-or-definition                     7           13.396982566  1.9138546524
> org-footnote-in-valid-context-p                               378         13.384084804  0.0354076317
> org-in-block-p                                                322         13.146482877  0.0408275865
> org-between-regexps-p                                         2576        12.544080215  0.0048695963
> org-footnote-at-reference-p                                   189         6.7601071689  0.0357677627
> org-footnote-at-definition-p                                  189         6.6263815400  0.0350602197
> org-element--parse-to                                         15          0.41858634    0.027905756
> org-element--cache-sync                                       18          0.3965463360  0.0220303520
> org-fontify-meta-lines-and-blocks                             14          0.3946110120  0.0281865008
> org-fontify-meta-lines-and-blocks-1                           14          0.3944775729  0.0281769695
> org-element--current-element                                  7           0.3642047120  0.0520292445
> ...
> --8<---------------cut here---------------end--------------->8---
>
> I didn't check how org-between-regexps-p and org-footnote-at-*-p are
> related, but those three seem to account for the lion's share of the
> time.
>
> BTW, org-src-font-lock-fontify-block calls font-lock-fontify-buffer
> which is not supposed to be called from lisp programs: the doc string
> suggests using font-lock-ensure or font-lock-flush. I tried the first
> but it did not make any difference in the speed. But I guess it should
> be changed.
>
> --
> Nick
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-07-22 23:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-14 18:15 long code blocks making Org Mode very slow Angus M
2015-07-14 19:41 ` Sebastien Vauban
2015-07-14 21:06   ` Angus M
2015-07-14 21:44 ` Nick Dokos
2015-07-14 23:39   ` Angus M
2015-07-15 12:22 ` Angus M
2015-07-17  1:10   ` Grant Rettke
2015-07-21 11:09     ` Angus M
2015-07-22  1:20       ` Grant Rettke
2015-07-22 10:09         ` Angus M
2015-07-22 12:41           ` Nick Dokos
2015-07-22 23:09             ` Grant Rettke

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).