summaryrefslogtreecommitdiff
path: root/src/regex_impl.hh
AgeCommit message (Collapse)Author
2025-07-08Replace std::unique_ptr with a custom implementationMaxime Coste
<memory> is a costly header we can avoid by just implementing UniquePtr ourselves, which is a pretty straightforward in modern C++, this saves around 10% of the compilation time here.
2025-07-07Copy instruction to local variable in step_current_threadMaxime Coste
This helps the compiler realize that data cannot change and does not need reloading, improving codegen slightly.
2025-07-07Use uint32_t for DualThreadStack indicesMaxime Coste
2025-07-07Add a CharRange regex op to optimize the common simple range caseMaxime Coste
Instead of jumping into the general CharClass code, detect simple [a-z] style ranges and use a specific op. Also detect when a range can be converted to ignore case
2025-07-07Avoid branches in ThreadedRegexVM::DualThreadStack iterationMaxime Coste
decrement and post_increment do not get cmov optimised as expected, we can avoid this altogether by taking advantage of the fact that capacity is always a power-of-two and we can hence use a bitwise and we can use a bitwise and to loop around capacity.
2025-02-04Revert "Use uint64_t for regex step"Maxime Coste
This got pushed by accident This reverts commit d92496449d0c9655253ad16363685bb8446dc582.
2025-01-22Use uint64_t for regex stepMaxime Coste
Its unclear that maintaining a small instruction size outweigh the cost of handling wrapping of the current_step every 64K codepoints, this makes the code simpler.
2024-12-10Code style tweak in regex_implMaxime Coste
2024-12-09Rework split between exec and exec_program methodMaxime Coste
Split last iteration out of the loop so that optimizer can elide most comparisons between pos and config.end as its always different in the loop and equal at last call.
2024-12-09Tweak inlining around thread stack push/pullsMaxime Coste
Ensure push/pulls operations are inlined except for the uncommon grow.
2024-12-05Fix parameter passing in find_next_startMaxime Coste
2024-12-04Various small code simplifications/tweaks in ThreadedRegexVMMaxime Coste
2024-12-01Add specific start desc optimization for single possible start byteMaxime Coste
Use tighter codegen for that pretty common use case.
2024-11-28Raise the regex idle function call period to every 16M codepointMaxime Coste
2024-11-04Fix backward regex search ending in DOTALLJohannes Altmanninger
I noticed that reverse searches ending in "." stopped working in version 2024.05.08: kak -n -e "exec %{%cfoobar<ret><esc>gj<a-/>foo.<ret>}' Bisects ca7471c25 (Compute StartDesc with an offset to effective start, 2024-03-18) which updated the find_next_start() logic for the forward case but not for backward case. Add a symmetrical change and test case, that seems to fix it. Not 100% sure if this is correct but feels so.
2024-08-12Reduce headers dependency graphMaxime Coste
Move more code into the implementation files to reduce the amount of code pulled by headers.
2024-08-12Remove void_t and use requires insteadMaxime Coste
2024-06-15Small code style tweakMaxime Coste
2024-06-15Store instruction pointers directly in ThreadedRegexVM::ThreadMaxime Coste
The previous tradeoff of having a very small Thread struct is not necessary anymore as we do not memcpy Threads on swap_next since d708b77186c1685dcbd2298246ada7d204acec2f. This requires offsets to be used instead of indices for jump/split ops.
2024-05-31Small regex code cleanupMaxime Coste
2024-04-01Add missing <bit> includeMaxime Coste
2024-03-22Match Op declaration order in switchesMaxime Coste
2024-03-22Make CompiledRegex not a RefCountableMaxime Coste
Keep this closer to the point of use, avoid pull ref_ptr.hpp into regex_impl.hpp
2024-03-21Compute StartDesc with an offset to effective startMaxime Coste
This means `.{2,4}foo` will now consider 4 or less before f as a start candidate instead of every characters
2024-03-21Only push a first instruction thread when on a potential startMaxime Coste
There is no need to push threads for each codepoint when we know they will fail as the current codepoint is not a start candidate.
2024-03-15Revert "Always allocate saves"Maxime Coste
This crashes in unit tests This reverts commit cde5f5a25838b2c9a2bf198b819a58d723b434a3.
2024-03-15Always allocate savesMaxime Coste
This sometimes allocates saves too eagerly, but it removes a branch in release saves that executes on every thread failing which seems slightly better.
2024-03-13Avoid clearing iterator buffer on saves allocationMaxime Coste
When creating a new save, we had to clear all iterators to have valid values. This operation is relatively costly because it gets optimized to a memset whose call overhead is pretty high (as we usually have less than 32 bytes to clear). Bypass this by storing a bitmap of valid iterators.
2024-03-13Simplify and accelerate start desc mapMaxime Coste
Store values for all possible bytes and fill utf8 multi byte start values when necessary.
2024-03-12Small cleanupMaxime Coste
2024-03-11Simplify Split regex op handling by swapping targetMaxime Coste
2024-03-11flatten ThreadedRegexVM::codepointMaxime Coste
Profiling shows that this does not always get the utf8::read_codepoint call inlined and that almost doubles the time spent in the function.
2024-03-07Reduce Save access indirectionsMaxime Coste
Most Save access are to modify the refcount. Now that the freelist is index based it is not necessary to keep Save objects at fixed memory locations.
2024-03-05Slight simplification of ThreadedRegexVM::execMaxime Coste
Remove redundant checking for end and double indirection to get instructions pointer.
2024-02-12Early reject regex instructions that were already scheduled this stepMaxime Coste
2024-02-11Do not decode utf8 while looking for next regex match start candidateMaxime Coste
If the first byte in the multi-byte utf8 sequence does not match, it means the "other" character is not set, so none of the sequence byte will match (as they are all with the MSB set). This tightens the critical loop which ends up running faster in most cases.
2023-06-27Unbreak build on ppcSergey Fedorov
Fixes: https://github.com/mawww/kakoune/issues/4937
2023-05-21Add an idle callback to be called regularly while regex matchingMaxime Coste
This paves the way towards being able to cancel long regex matching operations
2023-03-13Grow dual thread stack after pushing a thread on the next queueMaxime Coste
The previous code was assuming it was fine to push_next without growing, which used to be the case with the previous implementation because we always have poped the current thread that we try to push. However now that we use a ring-buffer, m_next_begin == m_next_end can either mean full, or empty. We solve this by assuming it means empty and never allowing the buffer to become full, which means we need to grow after pushing to next if we get full. Fixes #4859
2023-02-19Only decode current codepoint once per stepMaxime Coste
Instead of potentially decoding for each thread, always decode as its only slightly slower than finding next codepoint (which will be necessary anyway) and pass the codepoint to each thread.
2023-02-19Remove instructions from ExecConfigMaxime Coste
We can just compute whenever we reset last_step, which does not happen often and we know `forward` at compile time anyway
2023-02-19Optimize Regex CharacterClass matchingMaxime Coste
Take advantage of ranges sorting to early out, make the logic inline.
2023-02-14Fix broken corner cases in DualThreadStack::grow_ifnMaxime Coste
We only grow when the ring buffer is full, which allows for a nice simplification of the code. Tell grow_ifn if we pushed in current or next so that we can distinguish between filled by next or filled by current when m_current == m_next_begin
2023-02-14Refactor DualThreadStack as a RingBufferMaxime Coste
Instead of two stacks growing from the two ends of a buffer, use a ring buffer growing from the same mid spot. This avoids the costly memory copy every step when we set next threads as the current ones.
2023-02-13Remove scheduled optimization from ThreadedRegexVMMaxime Coste
This does not seem to actually speed up execution as threads will be dropped on next step anyway
2023-01-23Fix incorrect use of subject end/begin in regex executionMaxime Coste
This could lead to reading past subject string end in certain conditions Fixes #4794
2022-08-20Slight code style tweakMaxime Coste
2022-08-20Remove unnecessary utf8 decoding when looking for EOL in regexMaxime Coste
2022-08-20Refactor RegionsHighlighter to share regexesMaxime Coste
Instead of storing regexes in each regions, move them to the core highlighter in a hash map so that shared regexes between different regions are only applied once per update instead of once per region Also change iteration logic to apply all regex together to each changed lines to improve memory locality on big buffers. For the big_markdown.md file described in #4685 this reduces initial display time from 3.55s to 2.41s on my machine.
2022-08-05Reuse existing character classes when possible in regexMaxime Coste