-
Notifications
You must be signed in to change notification settings - Fork 88
State: Use std::vector
#97
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
Conversation
The vectors in `State` are never memory-mapped, so we can use `std::vector` instead of Marisa's vector. `std::vector` is smaller in size. This reduces `State` size from 80 bytes to 64 bytes, making it fit into a single cache line.
Perhaps in a future PR we can merge |
Please wait. |
I think the only exception it can throw is |
I was also wondering what the advantage of using |
I cannot remember the details. Even if the design is strange, we should not change the behavior for compatibility. |
5b32d39
to
8014250
Compare
I've added exception rethrowing. It increases For a major version bump, I think it'd be useful to consider not having this custom behaviour. Most code out there doesn't customize exceptions from the standard library this way, so it can be unexpected. For example, in the rare situation where a program actually handles allocation failure, there is usually an |
#ifndef MARISA_USE_EXCEPTIONS | ||
#if defined(__GNUC__) && !defined(__EXCEPTIONS) | ||
#define MARISA_USE_EXCEPTIONS 0 | ||
#elif defined(__clang__) && !defined(__cpp_exceptions) | ||
#define MARISA_USE_EXCEPTIONS 0 | ||
#elif defined(_MSC_VER) && !_HAS_EXCEPTIONS | ||
#define MARISA_USE_EXCEPTIONS 0 | ||
#else | ||
#define MARISA_USE_EXCEPTIONS 1 | ||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you assume an environment that disallows exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This supports such environments on GCC, Clang, and MSVC.
Exceptions are commonly disabled in environments such as Google and game development.
It is usually possible to compile individual libraries with exception support in these environments (as long as there is no exception handling in public headers) but it's pointless to catch-and-rethrow in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the information.
I didn't know this.
If exceptions are disabled, an application is terminated by an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if exceptions are disabled, then throwing an exception terminates the program.
Internally at Google we use explicit error handling with absl::Status (std::expected is the standard library equivalent in C++23).
There is generally no sensible way to handle things like out-of-memory errors or internal logic errors, so we do not try to handle them and simply allow the program to crash in those cases.
The vectors in
State
are never memory-mapped, so we can usestd::vector
instead of Marisa's vector.std::vector
is smaller in size (24 bytes vs 32 bytes).This reduces
State
size from 80 bytes to 64 bytes, making it fit into a single cache line.Benchmark on my machine shows a tiny improvement on a large file (best run of 3, so could just be noise):
Before:
After: