镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Change pure calls to use the faster unsafeDupablePerformIO - #117

Merged
bitonic merged 3 commits into
fpco:masterfrom
Ofenhed:faster_pure
Sep 20, 2020
Merged

bitonic merged 3 commits into
fpco:masterfrom
Ofenhed:faster_pure

Conversation

@Ofenhed

@Ofenhed Ofenhed commented Sep 19, 2020 •

Copy link
Copy Markdown
Contributor

Changing from unsafePerformIO to unsafeDupablePerformIO removes the thread safety of pure functions calls, which means that expensive CPU core memory synchronization is not performed. This means that pure functions may be called more than once if called at the same time from multiple threads. This change is safe as long as the documentation is followed, since the documentation asserts that called functions are not allowed to have side effects.

This fixes overhead reported in #115.

This may allow the ioCall to be executed twice. This is safe as long as
the documentation is followed, since the called function is not allowed
to have side effects.
@bitonic

bitonic commented Sep 20, 2020

Copy link
Copy Markdown
Collaborator

@Ofenhed thanks a lot for the investigation and fix.

Could you amend the "BEWARE" comment for pure? Maybe something along the lines of

Also note that the function might be called multiple times, given that unsafeDupablePerformIO is used to call the provided C code.

@bitonic

bitonic commented Sep 20, 2020

Copy link
Copy Markdown
Collaborator

Actually, re-reading the comment for unsafeDupablePerformIO, I think an ever longer caveat is warranted, something like

Also note that the function might be called multiple times, given that unsafeDupablePerformIO is used to call the provided C code. Please refer to the documentation for unsafeDupabelPerformIO for more details. unsafeDupablePerformIO is used to ensure good performance using the threaded runtime.

@bitonic

bitonic commented Sep 20, 2020

Copy link
Copy Markdown
Collaborator

Oh and last request -- please link the issue above the code usage of unsafeDupablePerformIO, so that we remember why it's there :).

@Ofenhed

Ofenhed commented Sep 20, 2020

Copy link
Copy Markdown
Contributor Author

I mostly used your text. What do you think about it now?

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