mathematica-autobackup icon indicating copy to clipboard operation
mathematica-autobackup copied to clipboard

Too slow in recent Mathematica 11

Open slizovskiy opened this issue 8 years ago • 10 comments

This seems to work MUCH slower than the ordinary "Save" button in Mathematica 11. I do not know, why. Probably, some other saving command should be used in the script. Thanks, Sergey

slizovskiy avatar Jan 04 '17 15:01 slizovskiy

Bummer! Sadly this was written in a much older version of Mathematica (7?) and hasn't been updated... If you can figure out an improvement please send a PR!

joshburkart avatar Jan 04 '17 16:01 joshburkart

Well, it's probably not the problem of Mathematica version. It's a problem that Export works very slowly on some large files, while NotebookSave works fast. On the other hand, we do not want to use NotebookSave. So, I am not sure how to improve.

On 04/01/17 16:08, Josh Burkart wrote:

Bummer! Sadly this was written in a much older version of Mathematica (7?) and hasn't been updated... If you can figure out an improvement please send a PR!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joshburkart/mathematica-autobackup/issues/1#issuecomment-270409784, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTdBtKsjcyQBYClSLn0fLtClei0GEuSks5rO8QPgaJpZM4LaxQO.

slizovskiy avatar Jan 04 '17 16:01 slizovskiy

Ah, actually, I remember noticing the speed difference too. Yep I'm not sure how to work around this either, other than by using smaller notebooks... Sorry!

joshburkart avatar Jan 05 '17 02:01 joshburkart

I have experienced this too. It is prominent in notebooks with lots of large images. This makes the FrontEnd hang for quite some time after evaluations when the timeout for the auto-save has been reached again.

Is there really no way to fix this? Why should we not use NotebookSave?

Masterxilo avatar Mar 03 '17 15:03 Masterxilo

I applied the following changes:

BackupName[file_String, num_Integer] :=
	file <> StringJoin @@ Table["~", {num}] <> ".nb";

Monitor[

NotebookSave[EvaluationNotebook[], Print@bakfile;bakfile];
(*Print@renameFile[bakfile<>".nb",bakfile];(*HACKFIX for NotebookSave adding .nb to .nb~*)*)

NotebookSave[EvaluationNotebook[], nbfile];(*HACKFIX for restoring the actual name instead of changing it*)
(*Export[bakfile, EvaluationNotebook[], "NB"]*)

,
				"Backing up " <> FileNameTake[nbfile] <> " to " <> FileNameTake[bakfile] <> "..."];

I had some trouble with RenameFile failing and NotebookSave adding .nb, but this works and seems much faster. This seems to do what I want.


Someone should report to WRI the NotebookSave <-> Export performance discrepancy.

Masterxilo avatar Mar 03 '17 16:03 Masterxilo

@Masterxilo Thanks for looking into this! My recollection was that using NotebookSave actually changes the location that Mathematica thinks the notebook is located, so that the next time the user clicks File -> Save it updates the backup rather than the original save location. Maybe I'm wrong though?

I believe the issue is that Export doesn't support incremental updates, and always resaves the whole thing, whereas NotebookSave only saves the new stuff. Again could be wrong.

If your solution works with no deleterious side effects then please consider sending a PR!

joshburkart avatar Mar 03 '17 16:03 joshburkart

Oh sorry, I see now that you got around this. Well in that case looks good to me! The slowness of using Export was always annoying to me too. PR?

joshburkart avatar Mar 03 '17 16:03 joshburkart

Sure!

I would prefer to get .nb~ and .nb~~ files though.

With my fix I get .nb~.nb and .nb~~.nb files which mix with the normal notebooks. I find that not too pretty.

Masterxilo avatar Mar 03 '17 18:03 Masterxilo

Ahh, yeah. Also, does this mean every time there's a backup, the notebook also gets saved? To its normal save path?

joshburkart avatar Mar 03 '17 19:03 joshburkart

Yes. This might be problematic if the notebook becomes corrupted (making the original and the backup unusable on the next backup).

Masterxilo avatar Mar 05 '17 21:03 Masterxilo