首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Saxon识别XSLT转换的性能瓶颈

使用Saxon识别XSLT转换的性能瓶颈
EN

Stack Overflow用户
提问于 2021-01-28 18:08:53
回答 1查看 525关注 0票数 1

有人能提供一些关于在转换中找出瓶颈的指导吗?

这是Saxon的node.js实现。我试图提高一些XML文档的转换速度,以便提供一个在60秒以下响应的同步API (230秒是Application的硬限制)。我还需要能够处理多达50 be大小的XML文件。

我运行了节点的构建分析器(https://nodejs.org/en/docs/guides/simple-profiling/)。但是,考虑到Saxon的免费版本的源代码并不是真正的人类可读的,所以很难理解结果。

我的密码

代码语言:javascript
复制
const path = require('path');
const SaxonJS = require('saxon-js');
const { loadCodelistsInMem } = require('../standards_cache/codelists');
const { writeFile } = require('../config/fileSystem');
const config = require('../config/config');
const { getStartTime, getElapsedTime } = require('../config/appInsights');

// Used for easy debugging the xslt stylesheet
// Runs iati.xslt transform on the supplied XML
const runTransform = async (sourceFile) => {
    try {
        const fileName = path.basename(sourceFile);

        const codelists = await loadCodelistsInMem();

        // this pulls the right array of SaxonJS resources from the resources object
        const collectionFinder = (url) => {
            if (url.includes('codelist')) {
                // get the right filepath (remove file:// and after the ?
                const versionPath = url.split('schemata/')[1].split('?')[0];
                if (codelists[versionPath]) return codelists[versionPath];
            }
            return [];
        };

        const start = getStartTime();
        const result = await SaxonJS.transform(
            {
                sourceFileName: sourceFile,
                stylesheetFileName: `${config.TMP_BASE_DIR}/data-quality/rules/iati.sef.json`,
                destination: 'serialized',
                collectionFinder,
                logLevel: 10,
            },
            'async'
        );
        console.log(`${getElapsedTime(start)} (s)`);

        await writeFile(`performance_tests/output/${fileName}`, result.principalResult);
    } catch (e) {
        console.log(e);
    }
};

runTransform('performance_tests/test_files/test8meg.xml');

控制台输出示例:

代码语言:javascript
复制
❯ node --prof utils/runTransform.js
SEF generated by Saxon-JS 2.0 at 2021-01-27T17:10:38.029Z with -target:JS -relocate:true
79.938 (s)
❯ node --prof-process isolate-0x102d7b000-19859-v8.log > v8_log.txt

文件:

最大性能违反者的V8日志片段:

代码语言:javascript
复制
 [Bottom up (heavy) profile]:
  Note: percentage shows a share of a particular caller in the total
  amount of its parent calls.
  Callers occupying less than 1.0% are not shown.

   ticks parent  name
  33729   52.5%  T __ZN2v88internal20Builtin_ConsoleClearEiPmPNS0_7IsolateE
   6901   20.5%    T __ZN2v88internal20Builtin_ConsoleClearEiPmPNS0_7IsolateE
   3500   50.7%      T __ZN2v88internal20Builtin_ConsoleClearEiPmPNS0_7IsolateE
   3197   91.3%        LazyCompile: *k /Users/nosvalds/Projects/validator-api/node_modules/saxon-js/SaxonJS2N.js:287:264
   3182   99.5%          LazyCompile: *<anonymous> /Users/nosvalds/Projects/validator-api/node_modules/saxon-js/SaxonJS2N.js:682:218
   2880   90.5%            LazyCompile: *d /Users/nosvalds/Projects/validator-api/node_modules/saxon-js/SaxonJS2N.js:734:184

非常感谢。关于这件事已经没有太多的资源可供我自己使用了。我也试过了:

  • 使用带有预解析的JSON的stylesheetInternal参数(并没有产生很大的影响)
  • 将文档拆分为只包含根<iati-activity>根元素中的一个活动<iati-activities>子元素的单独文档,分别对每个文档进行转换,并将它们放在一起--这最终花费了2x的时间。

最好的

耐克

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-28 20:35:40

你在https://saxonica.plan.io/boards/5/topics/8105?r=8106问了同样的问题,我也在那里回答了。我知道StackOverflow不喜欢只有链接的答案,但我更喜欢通过我们自己的支持渠道来支持用户,而不是在可能的情况下通过StackOverflow。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65942880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档