Skip to content

Commit

Permalink
Improve CWL parsing performance (#660)
Browse files Browse the repository at this point in the history
This commit improves CWL parsing by removing useless `deepcopy` of the
`context` object in the `CWLTranslator` class. The `context` dictionary
is now simply copied through the `copy.copy` method.
  • Loading branch information
GlassOfWhiskey authored Feb 14, 2025
1 parent 827c1a4 commit 01f6a23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions streamflow/cwl/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ def _create_command_output_processor(

def _create_context(version: str) -> MutableMapping[str, Any]:
return {
"default": {},
"elements": {},
"requirements": {},
"hints": {},
Expand Down Expand Up @@ -1580,7 +1579,7 @@ def _recursive_translate(
cwl_name_prefix: str,
):
# Update context
current_context = copy.deepcopy(context)
current_context = copy.copy(context)
for hint in cwl_element.hints or []:
if not isinstance(hint, MutableMapping):
current_context["hints"][hint.class_] = hint
Expand Down
17 changes: 13 additions & 4 deletions streamflow/cwl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,13 @@ def process_embedded_tool(
):
run_command = cwl_element.run
inner_context = dict(context)
# If the `run` options contains an inline CWL object
if cwl_utils.parser.is_process(run_command):
# Add the CWL version, which is not present by default
run_command.cwlVersion = context["version"]
# Process `stdout` and `stderr` directives
cwl_utils.parser.utils.convert_stdstreams_to_files(run_command)
# Compute the prefix of the inner CWL element
if ":" in run_command.id.split("#")[-1]:
cwl_step_name = get_name(
name_prefix,
Expand All @@ -734,19 +738,24 @@ def process_embedded_tool(
run_command.id,
preserve_cwl_prefix=True,
)
# Otherwise, the `run` options contains an URI
else:
run_command = cwl_element.loadingOptions.fetcher.urljoin(
cwl_element.loadingOptions.fileuri, run_command
)
# Fetch and translare the target file
run_command = cwl_utils.parser.load_document_by_uri(
run_command, loadingOptions=cwl_element.loadingOptions
path=cwl_element.loadingOptions.fetcher.urljoin(
base_url=cwl_element.loadingOptions.fileuri, url=run_command
),
loadingOptions=cwl_element.loadingOptions,
)
# Process `stdout` and `stderr` directives
cwl_utils.parser.utils.convert_stdstreams_to_files(run_command)
# Compute the prefix of the inner CWL element
inner_cwl_name_prefix = (
get_name(posixpath.sep, posixpath.sep, run_command.id)
if "#" in run_command.id
else posixpath.sep
)
# Set the inner CWL version, which may differ from the outer one
inner_context |= {"version": run_command.cwlVersion}
return run_command, inner_cwl_name_prefix, inner_context

Expand Down

0 comments on commit 01f6a23

Please sign in to comment.