Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance regression in xmlbuilder2 #70

Open
khromov opened this issue Jan 26, 2021 · 0 comments
Open

Performance regression in xmlbuilder2 #70

khromov opened this issue Jan 26, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@khromov
Copy link

khromov commented Jan 26, 2021

Describe the bug
After some performance profiling in our application it appears that xmlbuilder2 is approximately 2-3 times slower than xmlbuilder for our use case (XML sitemaps). Can something be done to get the performance more in-line with the original library?

To Reproduce
I'm attaching two test scripts below. When I run them I get these results:

✗ node xmlbuilder.js
Execution time: 3794ms

✗ node xmlbuilder2.js
Execution time: 10706ms

xmlbuilder.js

const builder = require("xmlbuilder");

const articles = [];
for (let i = 0; i < 500000; i += 1) {
  articles.push({
    loc: 'https://example.org',
    changefreq: 'weekly',
    priority: 0.6,
  });
}

const start = new Date();

const obj = {
  urlset: {
    '@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
    '@xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9',
    '@xsi:schemaLocation':
      'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
    url: [...articles],
  },
};

const feed = builder.create(obj, { encoding: 'utf-8' });
const output = feed.end({ pretty: false });

const end = new Date() - start;
console.info('Execution time: %dms', end);

xmlbuilder2.js

const { create } = require('xmlbuilder2');

const articles = [];
for (let i = 0; i < 500000; i += 1) {
  articles.push({
    loc: 'https://example.org',
    changefreq: 'weekly',
    priority: 0.6,
  });
}

const start = new Date();

const obj = {
  urlset: {
    '@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
    '@xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9',
    '@xsi:schemaLocation':
      'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
    url: [...articles],
  },
};

const doc = create(obj).dec({ encoding: 'UTF-8' });
const xml = doc.end({ prettyPrint: false });

const end = new Date() - start;
console.info('Execution time: %dms', end);

Expected behavior
Similar performance as the xmlbuilder library.

Version:

  • node.js: v14.15.1
  • xmlbuilder2 2.4.0
  • xmlbuilder 15.1.1
@khromov khromov added the bug Something isn't working label Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants