Summary: | __get_locale() is inefficient | ||
---|---|---|---|
Product: | Base System | Reporter: | Mark Johnston <markj> |
Component: | bin | Assignee: | Mark Johnston <markj> |
Status: | Closed FIXED | ||
Severity: | Affects Some People | CC: | emaste, kevans |
Priority: | --- | ||
Version: | CURRENT | ||
Hardware: | amd64 | ||
OS: | Any |
Description
Mark Johnston
2021-05-13 13:25:20 UTC
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=71ec05a21257e159f40d54e26ad0011bb19b5134 commit 71ec05a21257e159f40d54e26ad0011bb19b5134 Author: Cyril Zhang <cyril@freebsdfoundation.org> AuthorDate: 2021-05-13 12:55:06 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2021-05-13 13:33:19 +0000 sort: Cache value of MB_CUR_MAX Every usage of MB_CUR_MAX results in a call to __mb_cur_max. This is inefficient and redundant. Caching the value of MB_CUR_MAX in a global variable removes these calls and speeds up the runtime of sort. For numeric sorting, runtime is almost halved in some tests. PR: 255551 PR: 255840 Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30170 usr.bin/sort/bwstring.c | 54 ++++++++++++++++++++++++------------------------ usr.bin/sort/bwstring.h | 9 ++++---- usr.bin/sort/radixsort.c | 4 ++-- usr.bin/sort/sort.c | 6 +++++- usr.bin/sort/sort.h | 6 ++++++ 5 files changed, 45 insertions(+), 34 deletions(-) A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=df40dcbf7c794f5448c13e23670466658a620933 commit df40dcbf7c794f5448c13e23670466658a620933 Author: Cyril Zhang <cyril@freebsdfoundation.org> AuthorDate: 2021-05-13 12:55:06 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2021-05-20 13:15:43 +0000 sort: Cache value of MB_CUR_MAX Every usage of MB_CUR_MAX results in a call to __mb_cur_max. This is inefficient and redundant. Caching the value of MB_CUR_MAX in a global variable removes these calls and speeds up the runtime of sort. For numeric sorting, runtime is almost halved in some tests. PR: 255551 PR: 255840 Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30170 (cherry picked from commit 71ec05a21257e159f40d54e26ad0011bb19b5134) usr.bin/sort/bwstring.c | 54 ++++++++++++++++++++++++------------------------ usr.bin/sort/bwstring.h | 9 ++++---- usr.bin/sort/radixsort.c | 4 ++-- usr.bin/sort/sort.c | 6 +++++- usr.bin/sort/sort.h | 6 ++++++ 5 files changed, 45 insertions(+), 34 deletions(-) Configuring -ftls-model=initial-exec in the libc Makefile seems to fix it. I'm not sure if there might be some undesirable side-effects of that change though. OTOH, it is already used in jemalloc. A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9c97062b620137a1f7cad4c6b3fb030a396b3266 commit 9c97062b620137a1f7cad4c6b3fb030a396b3266 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2021-07-16 02:35:28 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2021-07-16 02:41:10 +0000 libc: Use the initial-exec TLS model This permits more efficient accesses of thread-local variables, which are heavily used at least by jemalloc and locale-aware code. Note that on amd64 and i386, jemalloc's thread-local variables already have their TLS model overridden by defining JEMALLOC_TLS_MODEL. For now the change is applied only to tested platforms, but should in principle be enabled everywhere. PR: 255840 Suggested by: jrtc27 Reviewed by: kib MFC after: 2 months Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31070 lib/libc/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=ad9f3a91d52105564dc32e5c0132377c74c3a204 commit ad9f3a91d52105564dc32e5c0132377c74c3a204 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2021-07-16 02:35:28 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2021-09-14 12:50:53 +0000 libc: Use the initial-exec TLS model This permits more efficient accesses of thread-local variables, which are heavily used at least by jemalloc and locale-aware code. Note that on amd64 and i386, jemalloc's thread-local variables already have their TLS model overridden by defining JEMALLOC_TLS_MODEL. For now the change is applied only to tested platforms, but should in principle be enabled everywhere. PR: 255840 Suggested by: jrtc27 Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit 9c97062b620137a1f7cad4c6b3fb030a396b3266) lib/libc/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) |