Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14029 closed bug (notabug)

japanese id and class selector is very slow

Reported by: osexp2003@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.1
Keywords: Cc:
Blocked by: Blocking:

Description

There are a bug in regular expression rquickExpr which cause japanese id, class not be recognized correctly so not get optimized with getElementById and getElementsByClassName.

Normal(OK) : $("#a") is translated to $(document.getElementById("a") Expect : $("#あ") will be translated to $(document.getElementById("あ") Result(NG) : $("#あ") is translated to $(document.querySelectorAll("#あ")

The same with class name. Normal(OK): $(".a") is translated to $(document.getElementsByClassName("a") Expect : $(".あ") will be translated to $(document.getElementsByClassName("あ") Result(NG) : $(".あ") is translated to $(document.querySelectorAll(".あ")

I changed 3 "[\w-]" in rquickExpr to "[\s.,+>~:\[]" so fixed the problem. line 68:

rquickExpr = /(?:\s*(<[\w\W]+>)[>]*|#([\w-]*))$/,

ー>

rquickExpr = /(?:\s*(<[\w\W]+>)[>]*|#([\s.,+>~:\[]*))$/,

line 969:

Easily-parseable/retrievable ID or TAG or CLASS selectors rquickExpr = /(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,

ー>

rquickExpr = /(?:#([\s.,+>~:\[]+)|(\w+)|\.([\s.,+>~:\[]+))$/,

I hope you commit this modification.

Change History (5)

comment:1 Changed 6 years ago by dmethvin

Owner: set to osexp2003@…
Status: newpending

Can you quantify "very slow" with a jsperf.com test? querySelectorAll isn't that slow.

rquickExpr isn't meant to catch all possible valid IDs, only those that can be easily recognized without the risk of misinterpreting escapes for example. I'm not sure if that change opens up any issues or not, but having the jsperf would be a good start to see what impact it has.

comment:2 in reply to:  1 Changed 6 years ago by anonymous

Replying to dmethvin:

Can you quantify "very slow" with a jsperf.com test? querySelectorAll isn't that slow.

I did test: http://jsperf.com/non-english-id-jquery-vs-english-id-jquery

rquickExpr isn't meant to catch all possible valid IDs, only those that can be easily recognized without the risk of misinterpreting escapes for example. I'm not sure if that change opens up any issues or not, but having the jsperf would be a good start to see what impact it has.

I understand. Please confirm it carefully.

comment:3 Changed 6 years ago by dmethvin

Owner: osexp2003@… deleted
Status: pendingnew

comment:4 Changed 6 years ago by timmywil

Resolution: notabug
Status: newclosed

It is slower, but it's not very slow. It takes the QSA path, which is what any selector not matching rquickExpr would attempt next. We could open up rquickExpr to all valid CSS identifiers, but we could see the quick path slow down for all selectors. Also, I don't see the need. If anyone disagrees, feel free to reopen.

comment:5 Changed 6 years ago by anonymous

in jquery 2, it is more slower in contrast to english id. But i can not include jquery 2 in jsperf.

Note: See TracTickets for help on using tickets.