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

Misc #85

Closed
wants to merge 4 commits into from
Closed

Misc #85

wants to merge 4 commits into from

Conversation

ice1000
Copy link
Contributor

@ice1000 ice1000 commented Feb 21, 2020

=w=

@ice1000 ice1000 requested a review from Him188 Feb 21, 2020
Him188
Copy link
Member

@Him188 Him188 commented on 831e3e8 Feb 21, 2020

Choose a reason for hiding this comment

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

这里用foreach会不会更好?这个不是普通 List, asSequence 会一个一个collect元素

https://github.com/mamoe/mirai/blob/master/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/LockFreeLinkedList.kt#L63

Him188
Copy link
Member

@Him188 Him188 commented on 831e3e8 Feb 21, 2020

Choose a reason for hiding this comment

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

这是个坑,0.24.0是 Jul. 2018,0.1.16是Nov, 2019,那么0.1.16应该是新版本?

https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-io

Him188
Copy link
Member

@Him188 Him188 commented on 831e3e8 Feb 21, 2020

Choose a reason for hiding this comment

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

ohh,之前就一直在想如何标注语言

ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented on 831e3e8 Feb 21, 2020

Choose a reason for hiding this comment

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

草, bintray 上没有 0.24 😨

ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented on 831e3e8 Feb 21, 2020

Choose a reason for hiding this comment

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

但是 sequence 是 lazy 的啊……

ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented on 831e3e8 Feb 21, 2020

Choose a reason for hiding this comment

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

:)

Him188
Copy link
Member

@Him188 Him188 commented on 831e3e8 Feb 22, 2020

Choose a reason for hiding this comment

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

但sequence是suspend地yield的不会影响吗
qqs这个链表会有两三千个元素..

ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented on 831e3e8 Feb 22, 2020

Choose a reason for hiding this comment

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

那我提议把 forEach 改成 asSequence(),这样就可以在合适的时候不继续获取后面的元素

Him188
Copy link
Member

@Him188 Him188 commented on 831e3e8 Feb 22, 2020

Choose a reason for hiding this comment

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

foreach是inline的,合适的时候就return了

ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented on 831e3e8 Feb 22, 2020

Choose a reason for hiding this comment

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

asSequence() 也是啊……

ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented on 831e3e8 Feb 22, 2020

Choose a reason for hiding this comment

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

Copy link
Member

@Him188 Him188 left a comment

See comments

@ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented Feb 26, 2020

根据 qq 群的讨论,决定把所有 forEach 换成 asSequence().forEach 而不是把 asSequence 改成 forEach 以便复用标准库的全套 API……

@ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented Feb 26, 2020

Review? @Him188

@Him188
Copy link
Member

@Him188 Him188 commented Feb 26, 2020

经测试(10k个元素, 获取100次最后一个元素统计用时毫秒), asSequence 要慢三倍.

foreach: 7
asSequence: 24
foreach: 6
asSequence: 21
foreach: 5
asSequence: 16
foreach: 5
asSequence: 14
foreach: 5
asSequence: 15
foreach: 5
asSequence: 14
foreach: 6
asSequence: 14
foreach: 4
asSequence: 15
foreach: 5
asSequence: 16

在实际使用中一个ContactList 会有 2k 个元素.
3 倍性能和 1 行复用, 是否选择性能会更好呢

我记得群里讨论结果是保留现有...
@ice1000

@ice1000
Copy link
Contributor Author

@ice1000 ice1000 commented Feb 26, 2020

嗯,那算了吧 (记忆出现了偏差

@ice1000 ice1000 closed this Feb 26, 2020
@Him188
Copy link
Member

@Him188 Him188 commented Feb 26, 2020

无论如何还是谢谢

mrhso pushed a commit to mrhso/mirai-moritaka that referenced this issue Jan 28, 2021
"帮主" -> "帮助"
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.

None yet

2 participants