mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-07-28 17:06:05 +00:00
* perf(sandbox): cache LocalSandbox path-rewrite regexes per instance LocalSandbox re-sorted path_mappings and re-compiled its path-rewrite regex on every tool call: _resolve_paths_in_command (every bash), _resolve_paths_in_content (every write_file), and _reverse_resolve_paths_in_output (every bash output / read_file). The inputs are derived solely from self.path_mappings, which is assigned once in __init__ and never mutated, so the work is identical every call. Compile the patterns once per sandbox via functools.cached_property and reuse them; hoist 'import re' to module scope. Behavior is unchanged — only the per-call sort+escape+compile on the agent's hot path is removed. Fixes #3647. Adds tests covering caching identity, unchanged rewriting, path-segment boundary matching, and the empty-mappings pass-through. * perf(sandbox): also cache resolved local paths and sorted mapping views Beyond the regex compilation, _find_path_mapping, _is_read_only_path, _resolve_path_with_mapping and _reverse_resolve_path re-sorted path_mappings and re-ran Path(local_path).resolve() (a filesystem syscall) on every call. Since path_mappings is immutable, cache the resolved local root per mapping and the two sorted views via cached_property and reuse them. Behavior is unchanged; the reverse-output pattern builder now reuses the same resolved-path cache.