[OE-core] [PATCH] spp: optimize strip_common_prefix function

zhangzl2013 zhangzl2013 at 126.com
Fri Aug 30 02:45:46 UTC 2019


On a Haswell Xeon 3.2GHz machine, iteration on each include_path costs ~12.5ms.
And the total time we can save at best is (0.0125s * n_patches * n_include_paths)

On 8/30/19 10:39 AM, Zhaolong Zhang wrote:
> strip_common_prefix() is the hot path that executes on every input file.
> This patch sorts and uniqs the $include_paths by length descreasingly.
> And with the sorted $include_paths, the for-loop inside strip_common_prefix
> can break earlier, thus kernel_metadata task can be sped up by multiple times.
>
> Signed-off-by: Zhaolong Zhang <zhangzl2013 at 126.com>
> ---
>   tools/spp | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
>
> diff --git a/tools/spp b/tools/spp
> index 1150ff3..cba52bb 100755
> --- a/tools/spp
> +++ b/tools/spp
> @@ -125,6 +125,7 @@ strip_common_prefix()
>   	if [ $this_len -lt $out_len ]; then
>   	    relocated_name=$t
>   	    out_len=$this_len
> +	    break
>   	fi
>   	# add a trailing slash to get corner cases where one may
>   	# have been added or not dropped
> @@ -133,6 +134,7 @@ strip_common_prefix()
>   	if [ $this_len -lt $out_len ]; then
>   	    relocated_name=$t
>   	    out_len=$this_len
> +	    break
>   	fi
>       done
>   
> @@ -297,6 +299,16 @@ infiles=$@
>   
>   processed_files=""
>   
> +# this function also removes duplicated lines by `sort -u`
> +sort_by_len_dec()
> +{
> +        for i in $@; do
> +                echo $i
> +        done | sort -u | awk '{ print length($0) " " $0; }' | sort -nr | cut -d ' ' -f 2-
> +}
> +
> +include_paths=$(sort_by_len_dec $include_paths)
> +
>   ##
>   ## create variables for use in scripts
>   ##



More information about the Openembedded-core mailing list