-1

I'm running a profiler on a page on my site, and the function "m" is running 1.2 seconds when I type three characters into a input masked SSN field. Trying to figure out what the function is that is being called so I can find it in the code and see why it is running so long.

One thing I have noticed is that the more elements on the page, the longer it takes to run.

Here is the function from the jquery:

m = function(b, e, f, g) {
    e = e || c;
    if (!g && !m.isXML(e)) {
        var h = /^(\w+$)|^.([\w-]+$)|^#([\w-]+$)/.exec(b);
        if (h && (e.nodeType === 1 || e.nodeType === 9)) {
            if (h[1]) return s(e.getElementsByTagName(b), f);
            if (h[2] && o.find.CLASS && e.getElementsByClassName) return s(e.getElementsByClassName(h[2]), f)
        }
        if (e.nodeType === 9) {
            if (b === "body" && e.body) return s([e.body], f);
            if (h && h[3]) {
                var i = e.getElementById(h[3]);
                if (!i || !i.parentNode) return s([], f);
                if (i.id === h[3]) return s([i], f)
            }
            try {
                return s(e.querySelectorAll(b), f)
            } catch (j) {}
        } else if (e.nodeType === 1 && e.nodeName.toLowerCase() !== "object") {
            var k = e,
                l = e.getAttribute("id"),
                n = l || d,
                p = e.parentNode,
                q = /^\s*[+~]/.test(b);
            l ? n = n.replace(/'/g, "\$&") : e.setAttribute("id", n), q && p && (e = e.parentNode);
            try {
                if (!q || p) return s(e.querySelectorAll("[id='" + n + "'] " + b), f)
            } catch (r) {} finally {
                l || k.removeAttribute("id")
            }
        }
    }
    return a(b, e, f, g)
};
Randy Slavey
  • 544
  • 4
  • 19
  • Generate a source map when minifying so that you know what your code is doing. – Denys Séguret May 26 '15 at 21:10
  • FYI this is jquery v1.7.1 – Randy Slavey May 26 '15 at 21:10
  • 2
    I suggest to use the unminified jQuery version and profile your code again. – Felix Kling May 26 '15 at 21:10
  • You should un-minify it. – But I'm Not A Wrapper Class May 26 '15 at 21:10
  • I'm not minifying. It's using the already minified jquery.min.js. It is not an environment I can substitute the un-minified version at my will. – Randy Slavey May 26 '15 at 21:11
  • There's entire sites dedicated to minifying/unminifying: http://unminify.com/ – But I'm Not A Wrapper Class May 26 '15 at 21:13
  • It would be easier to create an environment where you can substitute the un-minified version, than to try and de-minify it yourself. – gilly3 May 26 '15 at 21:14
  • @RandySlavey: You can substitute the minified jQuery with an unminified version *right in your browser*. Don't let the server environment restrict you. – Bergi May 26 '15 at 21:14
  • 2
    Searching the [source](http://code.jquery.com/jquery-1.7.1.js) for `isXML` reveals that the function is related to `Sizzle`, jQuery's selector engine. Unminifed source: https://github.com/jquery/sizzle/blob/1.7.1/sizzle.js#L1150-L1233 – Felix Kling May 26 '15 at 21:16
  • 1
    This previous question might help: [Replace some remote javascript file with a local debugging copy](http://stackoverflow.com/questions/7782069/replace-some-remote-javascript-file-with-a-local-debugging-copy-using-greasemonk?lq=1) – Yogi May 26 '15 at 21:21
  • Sorry if I sound crass, but how can you not replace the version of jQuery you're using? Simply point your HTML `` tag to the un-minified CDN version in the "Cloud". You really shouldn't use minified scripts when you're developing/debugging. You're just making your life a living hell otherwise. – Brett May 26 '15 at 21:22
  • 1
    To be clear, I'm not loading the jQuery in the page I'm working on. This is a large c# application using third party controls that are themselves loading and dependent upon specific versions of jQuery. While I could track down their libraries and determine where it's loading the minified jQuery and change it, I thought I'd ask here first in case anyone has run across this before. Thanks to felix-kling and @bergi for the leads towards sizzle. – Randy Slavey May 26 '15 at 21:35
  • You say this happens with IE8. Is that "real" IE8 or IE11 in emulator mode? While the emulator works well for general testing, I have noticed some odd behavior with JS that doesn't always show up in the real version. Just wanted to note that. – Yogi May 26 '15 at 21:52

1 Answers1

1

Since you already know that it's from jQuery 1.7.1, you can simply check its source and look out for salient patterns of the minified code, like the regexes, the .isXML method or one of the many DOM properties. You'll quickly find that it is the Sizzle function, the entry point to jQuery's Sizzle selector engine.

If this function takes up too much of your running time, this might be a hint that you are a) running an old browser b) using too complicated DOM selectors c) using too many selections in your code.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375