Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Check maxLineLen before trying to find matching bracket #1408

wants to merge 1 commit into from

2 participants


Match Brackets code tries to find matching bracket and then checks to see if line is too long. On a minified library such as less-1.3.0.min.js (47KB) this takes ~87 sec on MacBook Pro running MacOS 10.8. And there are much larger libraries out there!

It's much faster to check the line length first. This won't fix case where code has mixed long/short lines, but that does not seem to be common.

This is to fix Brackets issue 2991 and a few others.

Not sure if this is the best fix, but it should highlight the problem and get you close :)

@marijnh marijnh closed this pull request from a commit
@marijnh marijnh [matchbrackets addon] Don't fetch tokens on long lines
Without a bunch of more involved code, it has quadratic complexity, which
gets slow rather fast.

Closes #1408
@marijnh marijnh closed this in bcade67

The current test is there because setting a mark on a long line is very slow. Scanning through it isn't necessarily slow, but the way matchbrackets does it was causing problems. See attached patches. They largely fix the slowness and make it configurable which line length is skipped.


Verified that this fixes Brackets issues. Thanks.

@redmunds redmunds deleted the adobe:randy/fix-match-brackets branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2013
  1. @redmunds
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  addon/edit/matchbrackets.js
1  addon/edit/matchbrackets.js
@@ -9,6 +9,7 @@
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
function findMatchingBracket(cm) {
var cur = cm.getCursor(), line = cm.getLineHandle(cur.line), pos = - 1;
+ if (cm.getLine(cur.line).length > maxLineLen) return null;
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
if (!match) return null;
var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
Something went wrong with that request. Please try again.