Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bat freezes with extreme long lines (compact JSON) #1658

Closed
Tracked by #1751
dns2utf8 opened this issue May 19, 2021 · 9 comments
Closed
Tracked by #1751

bat freezes with extreme long lines (compact JSON) #1658

dns2utf8 opened this issue May 19, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@dns2utf8
Copy link

Hi all

I noticed that opening long json files makes bat get stuck.
For example the unpacked version of this file:
data.tar.gz

What did you expect to happen instead?

Maybe a warning or no highlighting.

How did you install bat?

cargo install -f bat

bat version and environment

Software version

bat 0.18.1 ()

Operating system

Linux 5.12.2-arch1-1

Command-line

bat --diagnostic 

Environment variables

SHELL=/bin/bash
PAGER=<not set>
LESS=<not set>
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=<not set>

Config file

Could not read contents of '/home/vp/.config/bat/config': No such file or directory (os error 2).

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version 
less 581.2 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
@dns2utf8 dns2utf8 added the bug Something isn't working label May 19, 2021
@sharkdp
Copy link
Owner

sharkdp commented Jun 14, 2021

Thank you for reporting this.

I would guess that it doesn't really freeze. It just takes a really long time. Could you please confirm that? Maybe run it with paging disabled (--paging=never)

@dns2utf8
Copy link
Author

Hello

Yes, technically with --paging=never it can open the file in 25 minutes.
Without it it takes almost 60 minutes ... I still think we should address it somehow.

Cheers,
Stefan

@sharkdp
Copy link
Owner

sharkdp commented Jun 14, 2021

Thank you.

Is it a file that you can share? (by attaching it to this issue?)

bat uses Sublime syntax files for highlighting (via the syntect library). They use regular expressions to matching certain syntax constructs. And matching time of regular expressions can sometimes be excessive (catastrophic backtracking) if the patterns are not optimized.

Related tickets: #221 (also JSON), #750, #677

@keith-hall
Copy link
Collaborator

You could try building bat with the regex-fancy feature instead of regex-onig and see if that makes a difference:

bat/Cargo.toml

Line 26 in 71f04dc

"regex-onig",

@dns2utf8
Copy link
Author

The file I used is this one, it is attached in the first part of the issue: https://github.com/sharkdp/bat/files/6510052/data.tar.gz

I did build it with this command:

cargo build --release --features application,regex-fancy

How do I run it with the regex-fancy now, I don't see any options that match?

@dns2utf8
Copy link
Author

I opened the file again:

time target/release/bat --paging=never /tmp/data.json
...
real    40m22.297s
user    13m3.482s
sys     26m52.858s

so the current configuration is worse than what I get when installing with cargo install bat

@sharkdp
Copy link
Owner

sharkdp commented Jul 25, 2021

Thank you. I added this ticket to the list of tasks in #1751.

@keith-hall
Copy link
Collaborator

Note that Sublime Text will simply not highlight lines which are longer than 16k characters, maybe we can do the same in bat...

@Enselic
Copy link
Collaborator

Enselic commented May 5, 2022

Closed by #2165

@Enselic Enselic closed this as completed May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants