Shapeshifter icon indicating copy to clipboard operation
Shapeshifter copied to clipboard

Copy and paste takes 56 seconds to complete

Open KoalaBear84 opened this issue 7 years ago • 24 comments

CopyThisContent.txt

If you copy the contents of this, it thinks that there are URLs in it, which it all tries to resolve. Also the Regex can't complete within time giving errors.

Example errors: System.Net.Sockets.SocketException (0x80004005): No such host is known

System.Text.RegularExpressions.RegexMatchTimeoutException: The RegEx engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors.

There are probably two things that needs to be done:

  1. Make all copy parsers / things async, don't lock / capture the clipboard, so the user can still paste it
  2. Better / faster regex (with async a little less important)
  3. Distinct list of URLs, so it might only be one url a 100 times or so (I didn't check how it is implemented right now)

KoalaBear84 avatar May 01 '18 13:05 KoalaBear84

I see it checks IsValidDomainAsync a lot of times for "Shapeshifter.exe" 😇

KoalaBear84 avatar May 01 '18 13:05 KoalaBear84

We should use https://github.com/0xcb/Re2.Net instead of C# Regular Expressions. RE2 is Google's regular expression library which is guaranteed to not go to an infinite loop and is secure to use.

The parsers should already be async, so that's a mistake if they are not.

ffMathy avatar May 01 '18 13:05 ffMathy

Yes, I see the whole parsing in itself is async, and also with yield, very good. I think it just captures the clipboard also while doing all this in async. So you cannot use the clipboard until Shapeshifter is done.

KoalaBear84 avatar May 01 '18 13:05 KoalaBear84

The thing is that we can never know if something is a website or not. So what Shapeshifter will try to do is to make a DNS resolve of all words in the clipboard to detect possible URLs to open. That should be very fast.

The errors you are seeing, are you sure they aren't just "first chance" exceptions? Those are exceptions that are actually caught, but displayed anyway while debugging.

ffMathy avatar May 01 '18 13:05 ffMathy

You are right about the first chance exceptions, and also luckily, else we have a lot of issues on Github 🚀

KoalaBear84 avatar May 01 '18 13:05 KoalaBear84

They have no NuGet package apparently. I have asked them to create one.

https://github.com/0xcb/Re2.Net/issues/4

ffMathy avatar May 02 '18 04:05 ffMathy

@KoalaBear84 I have trimmed the logs heavily in the latest pre-release that is up in half an hour or so (or you can pull latest develop now and see). I also disabled first-chance exceptions from popping up.

See if it makes debugging easier, and thank you so much for helping me debug!

ffMathy avatar May 02 '18 05:05 ffMathy

This should be switched to the time of copying and then persisted, instead of being generated dynamically upon switching to the item. That would solve a lot.

ffMathy avatar May 05 '18 15:05 ffMathy

I now greatly improved the regex performance by switching to RE2, but still leaving this here, as generating actions should never delay clipboard performance.

ffMathy avatar May 23 '18 16:05 ffMathy

True, it should leave the clipboard completely untouched for the current item and should only change something when you really use an item from the past. I don't know if that is possible? So when you do CTRL + C and just CTRL + V without holding it AND selecting a previous item, it should not touch the clipboard, otherwise than reading it, in async/locking if possible. But the last thing I don't know if that is possible.

KoalaBear84 avatar May 23 '18 18:05 KoalaBear84

While that may be faster, it is only faster in the scenario where you don't switch. I would much rather force the data through the same funnel always for consistency.

Here's what I'll do:

  1. When copying something, it'll start analyzing the data in the background to determine what kind of actions are available for that data. It will do this in an asynchronously queued manner.
  2. Once the analysis for an action is done, that action gets added to the list of available actions for that item.
  3. When the user shows the UI, we only display the actions that have finished analyzing for each item. So if one action is slow to analyze, the user just won't see that action.

This way, the user can always copy and switch right away, and because the data is not analyzed upon showing the UI but instead in the background when a new item has been copied, it should also feel faster.

Does that make sense?

ffMathy avatar May 23 '18 19:05 ffMathy

Yes. I think point 2 is already working, at least a little. When I tried it back then, the 'Open URLs' action was not yet shown, but after a couple of seconds it WAS, dynamically, while the overlay was open.

KoalaBear84 avatar May 23 '18 19:05 KoalaBear84

Can you see if the latest prerelease improves the performance? It really should. Issue should still be present though.

ffMathy avatar May 24 '18 04:05 ffMathy

Hmmm it is actually equally bad if not worse now. I opened #541 in addition to this to improve upon it.

ffMathy avatar May 24 '18 06:05 ffMathy

I didn't test it yet. But I guess indeed it will not make that much of a difference. It also is now because of the wrong data being scanned, and that results in an immense list of domains it wants to scan, and that takes a very long time.

KoalaBear84 avatar May 24 '18 06:05 KoalaBear84

All link related actions have now been entirely disabled until we stabilize all of this. There is no reason for it degrading the experience given how much they are used.

Prerelease up in a few minutes.

ffMathy avatar May 24 '18 14:05 ffMathy

@KoalaBear84 how is the latest prerelease performing? It should be significantly better, but there is still work to be done.

ffMathy avatar Jun 05 '18 20:06 ffMathy

This has now been fixed. Deferred action resolving has been implemented, and it's insanely fast and effective.

ffMathy avatar Jun 06 '18 22:06 ffMathy

Great. Will check it out.

KoalaBear84 avatar Jun 07 '18 05:06 KoalaBear84

Be sure to download it manually though because latest prereleases still have issues auto updating.

ffMathy avatar Jun 07 '18 06:06 ffMathy

Hmm, I did. shapeshifter-v6.2018.606.2854. It instantly crashes.

Also cleaned C:\Program Files\Shapeshifter and also tried to put Shapeshifter.exe directly in the right folder. But unfortunately nothing helps, cannot start it. Crash dump is generated.

KoalaBear84 avatar Jun 07 '18 08:06 KoalaBear84

Running it from the installation folder is not a good idea. Try cleaning the installation folder and removing it entirely, then run the downloaded file.

ffMathy avatar Jun 07 '18 08:06 ffMathy

Yes, I did that. Hmm, this is strange. But now I also deleted C:\Program Files\Shapeshifter and it works.

KoalaBear84 avatar Jun 07 '18 08:06 KoalaBear84

Hmm. I just copied 193 kB of a Shapeshifter log file. And eventually it showed the "Shapeshifter is not responding".

2018-06-08 12:14:57.115 [#15868] [Shapeshifter.WindowsDesktop.Infrastructure.Handles.Factories.PerformanceHandleFactory] [VRB]
Finished executing HasLinkWithConditionsAsync in 6589.7254 milliseconds.

2018-06-08 12:15:03.581 [#15868] [Shapeshifter.WindowsDesktop.Infrastructure.Handles.Factories.PerformanceHandleFactory] [VRB]
Finished executing HasLinkWithConditionsAsync in 6466.6556 milliseconds.

2018-06-08 12:15:10.127 [#15868] [Shapeshifter.WindowsDesktop.Infrastructure.Handles.Factories.PerformanceHandleFactory] [VRB]
Finished executing HasLinkWithConditionsAsync in 6545.4271 milliseconds.

2018-06-08 12:16:06.474 [#15868] [Shapeshifter.WindowsDesktop.Infrastructure.Handles.Factories.PerformanceHandleFactory] [VRB]
Finished executing HasLinkWithConditionsAsync in 56346.9137 milliseconds.

But it should be fully 'async'? Because it is still blocking Shapeshifter itself, the showing of an item copied (counter) and also it is locking the clipboard.

And if you would copy something twice the size of this it will take 2 minutes, and in that time you cannot access the clipboard in any way.

KoalaBear84 avatar Jun 08 '18 10:06 KoalaBear84