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

Windows: use __declspec(thread) TLS implementation, it is MUCH faster… #21810

Merged
merged 3 commits into from
May 8, 2023

Conversation

Araq
Copy link
Member

@Araq Araq commented May 8, 2023

… than _Thread_local [backport]

lib/nimbase.h Outdated Show resolved Hide resolved
@Araq Araq merged commit ec3bca8 into devel May 8, 2023
16 checks passed
@Araq Araq deleted the araq-fast-tls branch May 8, 2023 16:52
@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2023

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from ec3bca8

Hint: mm: orc; opt: speed; options: -d:release
167104 lines; 9.132s; 613.176MiB peakmem

@RSDuck
Copy link
Contributor

RSDuck commented May 8, 2023

Why did you change it to use __thread on mingw/GCC?

For me __thread didn't yield any improvement (with --threads:on more than halving the performance). But then I tried using __declspec(thread) and performance is now comparable to Linux, making --threads:on finally useable for me. Apparently this attribute is just ignored with a warning by GCC, so this is not valid.

EDIT 2: apparently gcc does not support native TLS on Windows at all (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80881), though atleast clang does, so I guess I have to stick with it.

@Araq
Copy link
Member Author

Araq commented May 9, 2023

I tried clang but even "hello world" crashes with clang on Windows for me. Which clang do you use? I'm willing to change the default C compiler that we ship with Nim if this finally solved this madness.

@RSDuck
Copy link
Contributor

RSDuck commented May 9, 2023

I'm using the one from msys2. While I like its integrated model with its package manager and closed environments, it's probably not for everyone.

One thing of note is that for TLS to work it's mingw clang environment has to be used, as in the default mingw x64 environment all the libraries (and clang) are compiled with gcc, so TLS emulation is used everywhere.

capocasa pushed a commit to capocasa/Nim that referenced this pull request May 15, 2023
nim-lang#21810)

* Windows: use __declspec(thread) TLS implementation, it is MUCH faster than _Thread_local [backport]

* Update lib/nimbase.h

* better fix
capocasa pushed a commit to capocasa/Nim that referenced this pull request May 16, 2023
nim-lang#21810)

* Windows: use __declspec(thread) TLS implementation, it is MUCH faster than _Thread_local [backport]

* Update lib/nimbase.h

* better fix
narimiran pushed a commit that referenced this pull request May 24, 2023
#21810)

* Windows: use __declspec(thread) TLS implementation, it is MUCH faster than _Thread_local [backport]

* Update lib/nimbase.h

* better fix

(cherry picked from commit ec3bca8)
bung87 pushed a commit to bung87/Nim that referenced this pull request Jul 29, 2023
nim-lang#21810)

* Windows: use __declspec(thread) TLS implementation, it is MUCH faster than _Thread_local [backport]

* Update lib/nimbase.h

* better fix
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