18

This seems like a really daft question, but I have a Python file that has a number in it that's a thousand digits long and that file seems to be running very slowly, I'm not sure if there's some kind of processing going on that I'm unaware of.

I press line up j and there's a definite pause of ~1 second thats very painful!

I only have this on the Python file though, it doesn't happen on others.

After deleting the number the file works normally again...

Here is the number :

number=("""7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450""")

It's not even a number really, its a string.

  • 2
    Confirmed here; doesn't happen if the file is .txt. Some syntax highlight regexp pattern going astray, I suppose. – Rmano Mar 22 '15 at 16:19
  • Since this is syntax highlighting related, the simple workaround would be to set synmaxcol to some limited number (such as the width of your terminal). – Slade Mar 22 '15 at 19:18
23

I can reproduce this with the syntax/python.vim that ships with Vim 7.4.663.

Using :syntime, this seems to be caused by the following syntax group / pattern:

TOTAL      COUNT  MATCH   SLOWEST     AVERAGE   NAME               PATTERN
73.870736   20     0       3.940215    3.693537  pythonNumber       \%(^\|\W\)\@<=\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>

You should report this problem to its maintainer (his name and email address is in the script's header).

Incidentally, I originally could not reproduce this, because I use an alternative syntax script from here. Switching to that (if it fits your requirements), would be a viable workaround, too.


Edit: Looking further into the probably cause, this seems to be due to pathological performance of the new NFA-based regexp engine. With :set regexpengine=1, I don't see that huge slowdown. So one possible workaround / fix would be switching to the old engine for that syntax match; this can be done by prepending \%#=1 to the pattern (cp. :help NFA).

  • thanks @Ingo, I've never reported anything before but I'm happy to do so. I have the syntax file in /usr/share/vim/vim74/syntax, the developer at the top is Neil Schemenauer <nas@python.ca>. Can I ask you; is this why you changed syntax files originally? Thanks – baxx Mar 22 '15 at 19:42
  • Yes, that's right; the latest version is from 2014 Jul 16, so it's likely it is still being maintained, and you'll get an answer from the author. You can point him to this, your question, as it already contains a nice reproducible example. – Ingo Karkat Mar 22 '15 at 20:31
  • I just found my alternative Python syntax somewhere somehow; I'm only rarely editing Python files, so I haven't given that much thought so far. – Ingo Karkat Mar 22 '15 at 20:32
  • thanks @Ingo, I've changed the syntax files and it's no longer being so slow. I'm afraid the regex engines are a bit beyond my understanding, I'll email the dev though, I'm happy to carry out any tests. – baxx Mar 22 '15 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.