From 4876f58ad60fd61b57699183734a27ac153b4492 Mon Sep 17 00:00:00 2001 From: YUART Date: Sat, 30 Sep 2023 21:35:06 +0200 Subject: [PATCH 1/3] Optimize tagged_post_count array to reset instead of allocating new --- v/related.v | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v/related.v b/v/related.v index 78bf023e..41c0f29d 100644 --- a/v/related.v +++ b/v/related.v @@ -39,10 +39,10 @@ fn main() { } mut all_related_posts := []RelatedPosts{cap: posts.len} + mut tagged_post_count := []int{len: posts.len, cap: posts.len} for i, post in posts { - // slower when preallocated - mut tagged_post_count := []int{len: posts.len, cap: posts.len} + unsafe { vmemset(tagged_post_count.data, 0, posts.len * tagged_post_count.element_size) } for tag in post.tags { for post_index in tag_map[tag] { From b2dfe63df0dd194e8359057dbf27553b58820f09 Mon Sep 17 00:00:00 2001 From: YUART Date: Sun, 1 Oct 2023 11:01:22 +0200 Subject: [PATCH 2/3] Optimize tagged_post_count array to reset instead of allocating new without unsafe --- v/related.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/v/related.v b/v/related.v index 41c0f29d..f1c42a2c 100644 --- a/v/related.v +++ b/v/related.v @@ -42,7 +42,9 @@ fn main() { mut tagged_post_count := []int{len: posts.len, cap: posts.len} for i, post in posts { - unsafe { vmemset(tagged_post_count.data, 0, posts.len * tagged_post_count.element_size) } + for j in 0 .. tagged_post_count.len { + tagged_post_count[j] = 0 + } for tag in post.tags { for post_index in tag_map[tag] { From cf3d7314964c9c892d03484b7abd9afe19bab64e Mon Sep 17 00:00:00 2001 From: YUART Date: Sun, 1 Oct 2023 11:03:21 +0200 Subject: [PATCH 3/3] Improve tagged_post_count init string --- v/related.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v/related.v b/v/related.v index f1c42a2c..46a16e3c 100644 --- a/v/related.v +++ b/v/related.v @@ -39,7 +39,7 @@ fn main() { } mut all_related_posts := []RelatedPosts{cap: posts.len} - mut tagged_post_count := []int{len: posts.len, cap: posts.len} + mut tagged_post_count := []int{len: posts.len} for i, post in posts { for j in 0 .. tagged_post_count.len {