Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8_12] improve strategy of expanding string for performance #341

Merged
merged 3 commits into from
Jul 18, 2024

Conversation

jingkaimori
Copy link
Contributor

@jingkaimori jingkaimori commented Jul 13, 2024

This pr ensure the layout consistency between array and string, by make member pointer appears at the same position of class, so that union inside tree will not be broken.

#331

class string{
int n;
int a_N;
char* a;
//...
}

template<class T>
class array<T>{
int n;
T* a;
//...
}

this pr

class string{
int n;
char* a;
int a_N;
//...
}

template<class T>
class array<T>{
int n;
T* a;
//...
}

Performance

Before

ns/op op/s err% total benchmark
28.76 34,766,499.89 1.9% 0.23 construct string
2.15 465,519,808.15 1.1% 0.24 equality of string
12.29 81,372,418.85 3.4% 0.24 equality of larger string
3.67 272,834,596.28 1.0% 0.24 compare string
6.77 147,721,592.92 1.4% 0.24 compare larger string
15.25 65,576,665.94 0.2% 0.24 slice string
25.84 38,706,819.98 0.6% 0.24 slice string with larger range
26.77 37,362,109.49 1.9% 0.24 concat string
14.44 69,248,803.63 2.7% 0.23 append string
3.95 253,250,191.20 0.7% 0.24 hash of string
31.15 32,099,101.32 0.5% 0.24 hash of larger string
2.45 408,268,298.94 1.1% 0.24 is quoted

After

ns/op op/s err% total benchmark
33.28 30,048,811.93 0.5% 0.24 construct string
2.10 476,358,528.82 1.9% 0.24 equality of string
12.61 79,290,902.83 3.3% 0.24 equality of larger string
3.69 271,309,979.88 1.5% 0.24 compare string
6.98 143,291,461.49 1.6% 0.24 compare larger string
15.86 63,070,424.48 1.1% 0.23 slice string
22.09 45,270,914.17 0.3% 0.24 slice string with larger range
25.83 38,707,374.61 2.1% 0.24 concat string
5.74 174,232,028.58 2.3% 0.22 append string
3.42 292,593,737.92 0.6% 0.24 hash of string
33.60 29,760,571.57 1.2% 0.24 hash of larger string
2.35 424,756,682.83 0.8% 0.24 is quoted

@jingkaimori jingkaimori requested a review from da-liii July 13, 2024 06:07
@da-liii
Copy link
Contributor

da-liii commented Jul 13, 2024

bench的结果在Pull Request的描述里面贴一下吧

@da-liii
Copy link
Contributor

da-liii commented Jul 13, 2024

依据PR里面的描述,前三项的性能退化了。

Kernel/Types/string.cpp Outdated Show resolved Hide resolved
@jingkaimori jingkaimori requested a review from da-liii July 13, 2024 14:04
@da-liii
Copy link
Contributor

da-liii commented Jul 13, 2024

在第三次提交下,性能应该有改善,需要一个新的性能对比,来判断性能上是否提升或者降低。

@jingkaimori
Copy link
Contributor Author

需要一个新的性能对比,来判断性能上是否提升或者降低。

已更新在pr的说明中

@da-liii
Copy link
Contributor

da-liii commented Jul 13, 2024

slice/concat/append 变快了,别的基本上差不多,略有变慢

@da-liii
Copy link
Contributor

da-liii commented Jul 13, 2024

这是之前的代码:30170ac

@da-liii
Copy link
Contributor

da-liii commented Jul 13, 2024

在PR描述或者代码里面写一下,这个pr和 #331 有什么区别,如何做到避免内存问题的

Copy link
Contributor

@da-liii da-liii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@da-liii da-liii changed the title Jingkaimori/string backport [8_12] improve strategy of expanding string for performance Jul 14, 2024
@da-liii da-liii merged commit 3e42c62 into main Jul 18, 2024
12 checks passed
@da-liii da-liii deleted the jingkaimori/string-backport branch July 18, 2024 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants