diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index f1c15e197d96bcd0d4cbbc00b5efbd5e54a50a23..034c49a905918fc13f37ed014892b6b8f00e7f5a 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1278,8 +1278,10 @@ class View {
 
 	private function assertPathLength($path) {
 		$maxLen = min(PHP_MAXPATHLEN, 4000);
-		$pathLen = strlen($path);
-		if ($pathLen > $maxLen) {
+		// Check for the string length - performed using isset() instead of strlen()
+		// because isset() is about 5x-40x faster.
+		if(isset($path[$maxLen])) {
+			$pathLen = strlen($path);
 			throw new \OCP\Files\InvalidPathException("Path length($pathLen) exceeds max path length($maxLen): $path");
 		}
 	}