From fcb529766049a3ab75cd9a0de4603c0a815c5a0b Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 Jan 2020 00:21:49 +0100 Subject: [PATCH] Use parallel stream to process YANG text files When we are examining local YANG files, we are also performing first step of parsing to determine what the module/revision is without relying on the file name. This process can take quite some time if the models are large and/or there are many of them. Since each file is independent at this stage, use a parallel stream (and hence common FJ pool) to perform this task in multiple threads before moving on to processing. JIRA: YANGTOOLS-1062 Change-Id: I31cee2aa7f313052565ba723cf4c52566821a625 Signed-off-by: Robert Varga --- .../plugin/YangToSourcesProcessor.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java index 2879f03fd9..4490cccb03 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java @@ -267,10 +267,22 @@ class YangToSourcesProcessor { final YangParser parser = parserFactory.createParser(parserMode); final List sourcesInProject = new ArrayList<>(yangFilesInProject.size()); - for (final File f : yangFilesInProject) { - final YangTextSchemaSource textSource = YangTextSchemaSource.forFile(f); - final ASTSchemaSource astSource = TextToASTTransformer.transformText(textSource); + final List> parsed = yangFilesInProject.parallelStream() + .map(file -> { + final YangTextSchemaSource textSource = YangTextSchemaSource.forFile(file); + try { + return new SimpleImmutableEntry<>(textSource, + TextToASTTransformer.transformText(textSource)); + } catch (YangSyntaxErrorException | SchemaSourceException | IOException e) { + throw new IllegalArgumentException("Failed to parse " + file, e); + } + }) + .collect(Collectors.toList()); + + for (final Entry entry : parsed) { + final YangTextSchemaSource textSource = entry.getKey(); + final ASTSchemaSource astSource = entry.getValue(); parser.addSource(astSource); if (!astSource.getIdentifier().equals(textSource.getIdentifier())) { @@ -288,7 +300,7 @@ class YangToSourcesProcessor { final ProcessorModuleReactor reactor = new ProcessorModuleReactor(parser, sourcesInProject, dependencies); LOG.debug("Initialized reactor {} with {}", reactor, yangFilesInProject); return Optional.of(reactor); - } catch (IOException | SchemaSourceException | YangSyntaxErrorException | RuntimeException e) { + } catch (IOException | YangSyntaxErrorException | RuntimeException e) { // MojoExecutionException is thrown since execution cannot continue LOG.error("{} Unable to parse YANG files from {}", LOG_PREFIX, yangFilesRootDir, e); Throwable rootCause = Throwables.getRootCause(e); -- 2.36.6