micro-editor / micro-editor/micro

main.Buffer.ReOpen hangs for large binary files

Open
#1,209 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
29.6k
Forks
1.4k
Avg merge
2d 18h
Merged PRs (30d)
10

Description

Description of the problem or steps to reproduce

Call main.Buffer.ReOpen on a large binary file (e.g. the micro binary) and observe it hang completely.

You can try this out yourself by installing the filemanager plugin, running the tree command and attempting to open the micro binary with TAB.

Specifications

You can use micro -version to get the commit hash.

Commit hash: de35d00ba7880540074b6ce500bbd1b82e986f61
OS: Ubuntu 18.04.1 LTS
Terminal: GNOME Terminal

Other Information

I've narrowed this down to the String() method of main.LineArray:

https://github.com/zyedidia/micro/blob/de35d00ba7880540074b6ce500bbd1b82e986f61/cmd/micro/lineArray.go#L118-L128

This method is called by main.EventHandler.ApplyDiff() (L89)

https://github.com/zyedidia/micro/blob/de35d00ba7880540074b6ce500bbd1b82e986f61/cmd/micro/eventhandler.go#L83-L101

The issue is that eh.buf (in the case of the micro binary) is about 100k elements long, causing String() to pretty much crash the whole thing.

Attempted Fix

I tried changing this method to use the new strings.Builder but it did not seem to help.

Potential Solution

One potential solution I came up with is checking the equality of the old and new line arrays before diffing them, which is slow (takes maybe 1/4 a second) but doesn't hang micro completely.


This issues causes #1208 (filemanager calls ReOpen when opening a file for some reason).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cmd/micro/lineArray.go, especially LineArray.String(), then trace how it is called from EventHandler.ApplyDiff in cmd/micro/eventhandler.go. Reproduce the problem through the filemanager plugin by opening a large binary with tree and TAB; done means ReOpen completes without hanging on large binary files.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.