2015-05-26 22:43 GMT+02:00 Chet Ramey <[email protected]>:
> I did a couple of things.  I added an inline _rl_wcwidth function that
> returns 1 for all printable ASCII characters and calls the system wcwidth
> for the rest.  That should help, though it doesn't do anything for
> characters between 128 and 256.
>
> The second thing is this experimental patch to text.c that uses the
> heuristic you suggested: it assumes that a call to rl_insert will be
> followed by other calls to rl_insert and tries to read ahead in the
> input stream as long as the character read maps to self-insert.  I've
> attached that for folks to experiment with.

I tested it with "åååå " x 50000 (so 250k characters, but perhaps 450k
bytes) and it takes about a second now compared to several minutes
before. Awesome! Thanks!

I probably hit the slowdown weekly at the moment, pasting long SQL
queries into Postgres.

Here's a profile, just for reference:

  23,38%  fileman  fileman            [.] _rl_find_prev_mbchar
   5,47%  fileman  libc-2.19.so       [.] __gconv_transform_utf8_internal
   4,91%  fileman  [kernel.kallsyms]  [k] memset
   4,15%  fileman  [kernel.kallsyms]  [k] do_select
   3,47%  fileman  [kernel.kallsyms]  [k] _raw_spin_lock_irqsave
   3,25%  fileman  [kernel.kallsyms]  [k] sysenter_past_esp
   3,01%  fileman  [kernel.kallsyms]  [k] __copy_from_user_ll
   2,69%  fileman  [kernel.kallsyms]  [k] __copy_to_user_ll
   2,38%  fileman  [kernel.kallsyms]  [k] core_sys_select
   2,15%  fileman  [kernel.kallsyms]  [k] n_tty_read
   2,07%  fileman  [kernel.kallsyms]  [k] _raw_spin_unlock_irqrestore
   1,99%  fileman  fileman            [.] _rl_input_available
   1,94%  fileman  libc-2.19.so       [.] __mbrtowc
   1,55%  fileman  libc-2.19.so       [.] wcwidth
   1,39%  fileman  [kernel.kallsyms]  [k] ldsem_down_read
   1,26%  fileman  [kernel.kallsyms]  [k] copy_from_read_buf
   1,16%  fileman  [kernel.kallsyms]  [k] enqueue_task_fair
   1,15%  fileman  fileman            [.] rl_insert_text

With your fix, if I'm not mistaken, readline is now calling wcwidth
and friends 250,000 times compared to around 250000^2 / 2 ~
31,250,000,000 times previously.


Ole

_______________________________________________
Bug-readline mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-readline

Reply via email to