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

Spyder is slow to start due to big history file #7080

Closed
impact27 opened this issue May 7, 2018 · 18 comments
Closed

Spyder is slow to start due to big history file #7080

impact27 opened this issue May 7, 2018 · 18 comments

Comments

@impact27
Copy link
Contributor

impact27 commented May 7, 2018

When starting, spyder reads a 10Mo text file in ~/.spyder-py3 called history.py.
That takes ~15s, which is a painfully noticeable start-up time.
Is there an option to limit how far back I want to load the history?

The easy work-around is for me to edit manually this file, but if an user is not aware of this, he might get annoyed by the start-up time.
I can go from 22s to 6s start-up time, which is not fast but way less annoying.

Also closing spyder takes almost 9s. I couldn't figure out why. If I have to restart spyder, usually I just kill it to avoid having to wait.

Python 3.6.5 64bits, Qt 5.10.1, PyQt5 5.10.1 on Darwin
OSX 10.13.4

@impact27
Copy link
Contributor Author

impact27 commented May 7, 2018

For closing, I can go down to 2s by not having any ipython console opened, and down to <1s by changing self.process.waitForFinished(1000) to self.process.waitForFinished(100) in the close function of AsyncClient in plugin_client.py.

@impact27
Copy link
Contributor Author

impact27 commented May 7, 2018

Upon further investigation, I would say that when a new client is added to ipythonconsole, a new QtWebEngineProcess is added but not closed when the client is removed.
If I open and then close 3 iPython tabs:
screen shot 2018-05-07 at 15 29 31
First I have 1 main Python process, 2 other python process and 2 QtWebEngineProcess.
If I close spyder now it will be fast.
screen shot 2018-05-07 at 15 30 39
Then I open 3 tabs. I get 3 extra python process, and 3 extra QtWebEngineProcess. Spyder will need to wait for some kind of timeout before closing (5-15 s usually).
screen shot 2018-05-07 at 15 31 23
The three tabs are closed. The 3 extra python process disappeared, but not the QtWebEngineProcess. Spyder is still slow to close.

@ccordoba12
Copy link
Member

Python 3.6.5 64bits, Qt 5.10.1, PyQt5 5.10.1 on Darwin

Please downgrade to Qt 5.9 and try again. There are multiple reports that PyQt apps don't work well with this version.

@ccordoba12
Copy link
Member

When starting, spyder reads a 10Mo text file in ~/.spyder-py3 called history.py.
That takes ~15s, which is a painfully noticeable start-up time.
Is there an option to limit how far back I want to load the history?

We have plans to improve this for Spyder 4, but I'm unsure what to do about Spyder 3. There's a config option to limit the number of lines of history.py, so I guess you're evaluating very long lines. Is that the case?

@impact27
Copy link
Contributor Author

impact27 commented May 8, 2018 via email

@impact27
Copy link
Contributor Author

impact27 commented May 8, 2018

My problem is that until I spent time looking into that, I didn't know why spyder was so slow to start. So this is not a good experience for an everyday user. I would probably try to show a message like: "Spyder is slow to start, here what you can do"?

My history is 225k lines, but the setting says 100 max. My understanding of that is:

When spyder is starting, mainwindow.py run_spyder is called. Somewhere in main.setup(), shell.py's load_history is called. This history is loaded from '/Users/quentinpeter/.spyder-py3/history_internal.py'. This file is empty, so the length is 0. Then the limit is applied, but 0 < 100 so it keeps on going.
Later, main.post_visible_setup() is called. When loading ipython, history.py add_history is called. This loads
'/Users/quentinpeter/.spyder-py3/history.py', which is 200k lines long. The length is never compared to the CONF.get('historylog', 'max_entries') settings, so this file gets to grow as much as it wants.

So either '/Users/quentinpeter/.spyder-py3/history_internal.py' and '/Users/quentinpeter/.spyder-py3/history.py' should be the same thing, or CONF.get('historylog', 'max_entries') should be applied on '/Users/quentinpeter/.spyder-py3/history.py'. I don't know which one is best.

@impact27
Copy link
Contributor Author

impact27 commented May 8, 2018

This seems to be two unrelated issues. Should I open a new issue?

@ccordoba12
Copy link
Member

ccordoba12 commented May 9, 2018

My history is 225k lines, but the setting says 100 max. My understanding of that is:

Your understanding seems to be correct. Could you open a PR for this? It'd be greatly appreciated!

Should I open a new issue?

Yes, please open a new issue about the WebEngineProcess'es.

@ccordoba12 ccordoba12 changed the title Spyder is slow to start and stop Spyder is slow to start due to big history file May 9, 2018
@impact27
Copy link
Contributor Author

impact27 commented May 9, 2018

What does the history_internal.py file stores? Is the bug that history_internal.py should be the same as history.py or should I just apply the max_entries to history.py as well?

@impact27
Copy link
Contributor Author

impact27 commented May 9, 2018

I opened #7091

@jitseniesen
Copy link
Member

What does the history_internal.py file stores? Is the bug that history_internal.py should be the same as history.py or should I just apply the max_entries to history.py as well?

It's not my code, but I'm pretty sure that history_internal.py stores the history of the internal console (called InternalShell in code). I think the max_entries setting shold be appled to history.py as well.

@ccordoba12
Copy link
Member

Yes, @jitseniesen is right.

@impact27
Copy link
Contributor Author

The history is duplicated. Why is the history not just loaded from the ipython "history.sqlite"? Is there anyone not using the ipython console? Also this is a bit confusing because the "history log" is not related to what you can actually access by pressing "up" in the ipython console.

@ccordoba12
Copy link
Member

Also this is a bit confusing because the "history log" is not related to what you can actually access by pressing "up" in the ipython console.

What do you mean buy this? We save the contents of every command introduced in our consoles in the history log.

@impact27
Copy link
Contributor Author

If I delete the ~/.spyder-py3/history.py file, I can still access the history from the ipython console, but not from the history widget. Also the ipython history saves blocks, not lines. The history.py file doesn't know anything about blocks.

When you press up, ipython gets data from ~/.ipython/profile_default/history.sqlite. When a command is executed, it is saved in ~/.ipython/profile_default/history.sqlite and in ~/.spyder-py3/history.py. history.py is useless for ipython and might not be consistent with history.sqlite.

So while we do save every command in history.py, they are duplicated in history.sqlite. If I edit history.py to say "This is a test", I will only see "This is a test" in the history log, but pressing up in ipython will give me the previous commands I used.

My questions are therefore:

  • Is history.py only used for the "History log" widget?
  • Should the "History log" widget instead display the content of history.sqlite?
  • Is anyone using a regular python console, as opposed to IPython?
  • What is the best way to access ipython history? I don't want to read the file directly as the API might change.

@ccordoba12
Copy link
Member

My answers:

Is history.py only used for the "History log" widget?

Yes.

Should the "History log" widget instead display the content of history.sqlite?

Yeah, that would be better. We could get rid of history.py and simply access that database to populate the History Log.

However, we haven't had time to do it but it'd be a very nice thing to do for Spyder 4.

Is anyone using a regular python console, as opposed to IPython?

No, the Python console was removed in 3.2

What is the best way to access ipython history?

No idea. @takluyver, could you give us a hand here? I think you are the one who knows best how to access history.sqlite.

@takluyver
Copy link
Contributor

For read-only access, you want a HistoryAccessor object. The HistoryManager subclass has write functionality too.

This was one of the first bits I worked on in IPython :-)

@ccordoba12
Copy link
Member

Thanks a lot Thomas!

ccordoba12 added a commit that referenced this issue Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants