Jsoup.parse takes 10x more time on 19+ android devices

Viewed 317

For some reason using Jsoup.parse takes 10x more time on kitkat devices than on older devices, at first I thought it was related to ART runtime, but changing back to dalvik didn't help

Here is the code I'm using:

        downloadedHtml = NetworkHelper.downloadString("https://en.m.wikipedia.org/wiki/Dusseldorf");

        AppLog.i("Downloaded data, Jsoup is parsing the html");

        hDoc = Jsoup.parse(downloadedHtml);

        Element htmlElement = hDoc.select("html").first();

        String langCode = htmlElement.attributes().get("lang");

        ArticleInfo articleInfo = new ArticleInfo(getWikiLanguage(langCode), langCode, href);

        article = new Article(articleInfo, href);

        String title = hDoc.getElementById("section_0").text();

        article.set_title(title);

        Document documentNode = hDoc.ownerDocument(); 

        Elements contents = documentNode.getElementsByClass("content");

        if (contents == null || contents.isEmpty())
            throw new IllegalArgumentException("content");

        Element content = contents.first();

        Elements imgElements = content.select("img");

        Element htmlNode;

        for (int i = 0; i < imgElements.size(); i++)
        {
            htmlNode = imgElements.get(i);

            if (!htmlNode.hasAttr("src"))
                continue;

            String src = htmlNode.attr("src");

            if (src.startsWith("//"))
                htmlNode.attr("src", String.format("http:%s", src));
            //else
            //throw new UnsupportedOperationException();
        }

        //get section headings

        Elements headlines = documentNode.getElementsByClass("mw-headline");

        if (headlines != null)
        {
            Element headline;

            for (int i = 0; i < headlines.size(); i++)
            {
                headline = headlines.get(i);

                String headline_link = headline.id();
                String headline_title = headline.text();

                SectionHeadline sectionHeadline = new SectionHeadline(headline_title, headline_link);
                article.get_sectionHeadlines().add(sectionHeadline);
            }
        }

        article.set_html(content.outerHtml());

        //get languages
        //language list

        Element languageSection = content.getElementById("mw-mf-language-section");

        if (languageSection != null)
        {
            Elements languageLinks = languageSection.select("li");

            Element languageLink;

            for (int i = 0; i < languageLinks.size(); i++)
            {
                languageLink = languageLinks.get(i);

                Element link = null;
                Elements ls = languageLink.select("a");

                if (ls == null || ls.size() == 0)
                    continue;

                link = ls.first();

                if (!link.hasAttr("href"))
                    continue;

                String linkHref = link.attr("href");

                if (linkHref != null && link.text() != null)
                {
                    String languageCode = link.attr("lang");

                    if (linkHref.startsWith("//"))
                        linkHref = String.format("http:%s", linkHref);

                    ArticleInfo languageInfo = new ArticleInfo(getWikiLanguage(languageCode), languageCode, linkHref);

                    if (languageInfo.get_language() == "Unknown")
                        continue;

                    article.get_languages().add(languageInfo);
                }
            }

        }

Any ideas what the problem may be?

1 Answers
Related