quasilyte
Repos
114
Followers
578
Following
63

The most opinionated Go source code linter for code audit.

1446
105

Define and run pattern-based custom linting rules.

639
36

Go mascot image constructor. Create your cute own gopher.

142
8

Syntax-aware grep for PHP code.

215
10

Source code analyzer that helps you to make your Go programs more consistent.

314
12

The code used to serve gocorpus application

49
1

Events

started
Created at 19 hours ago
delete branch
quasilyte delete branch quasilyte/implode_optimization
Created at 1 day ago
push

[runtime] add count=1 special case for implode() function (#651)

Some stats from a real-world app:

~0.7% calls with count=0
~56%  calls with count=1
~43%  calls with count>1

The count=0 case can be optimized by returning the empty string right away, but since it's so rare, this change is not applied. Our allocator knows how to allocate an empty-sized string efficiently.

The count=1 case can be optimized by returning the sole array element. This may require a to_string conversion, so we're wrapping it in f$strval. Since this is a frequent case, this optimization will be applied.

This optimization is quite common in languages with immutable (or COW) strings:

https://cs.opensource.google/go/go/+/refs/tags/go1.19.2:src/strings/strings.go;l=435

Benchmark results:

name               old time/op    new time/op    delta
Implode::Implode1    58.0ns ± 0%    24.9ns ± 4%   -57.07%  (p=0.000 n=8+10)
Implode::Implode3    84.1ns ± 3%    85.6ns ± 1%    +1.78%  (p=0.021 n=10+10)
[Geo mean]           69.8ns         46.2ns        -33.90%

name               old alloc/op   new alloc/op   delta
Implode::Implode1     32.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Implode::Implode3     56.0B ± 0%     56.0B ± 0%         ~  (all equal)

name               old allocs/op  new allocs/op  delta
Implode::Implode1      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Implode::Implode3      1.00 ± 0%      1.00 ± 0%         ~  (all equal)

The case for count!=1 gets extra 2-3ns execution time due to the extra size check. The main benefit of this change is heap allocations reduction.

Created at 1 day ago
pull request closed
[runtime] add count=1 special case for `implode()` function

Some stats from a real-world app:

~0.7% calls with count=0
~56%  calls with count=1
~43%  calls with count>1

The count=0 case can be optimized by returning the empty string right away, but since it's so rare, this change is not applied. Our allocator knows how to allocate an empty-sized string efficiently.

The count=1 case can be optimized by returning the sole array element. This may require a to_string conversion, so we're wrapping it in f$strval. Since this is a frequent case, this optimization will be applied.

This optimization is quite common in languages with immutable (or COW) strings:

https://cs.opensource.google/go/go/+/refs/tags/go1.19.2:src/strings/strings.go;l=435

Benchmark results:

name               old time/op    new time/op    delta
Implode::Implode1    58.0ns ± 0%    24.9ns ± 4%   -57.07%  (p=0.000 n=8+10)
Implode::Implode3    84.1ns ± 3%    85.6ns ± 1%    +1.78%  (p=0.021 n=10+10)
[Geo mean]           69.8ns         46.2ns        -33.90%

name               old alloc/op   new alloc/op   delta
Implode::Implode1     32.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Implode::Implode3     56.0B ± 0%     56.0B ± 0%         ~  (all equal)

name               old allocs/op  new allocs/op  delta
Implode::Implode1      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Implode::Implode3      1.00 ± 0%      1.00 ± 0%         ~  (all equal)

The case for count!=1 gets extra 2-3ns execution time due to the extra size check. The main benefit of this change is heap allocations reduction.

Created at 1 day ago
push

[compiler] add optimization rules

Related changes:

  • made hrtime_int and other specialized function internal
  • moved hrtime and microtime replacement to the rewrite rules
  • introduced a tmp_string concept
  • added a string::append(tmp_string) overloading
  • added wrap_substr_args to re-use substr start+length handling (it's weird)
  • added new kphp phpdoc tags for internal use
  • restriction-isset learned how to check the optimized functions
  • added explode specializations that return tuples, etc
  • added internal functions aliases if they're replacing existing functions
    • for example, instead of microtime_string the user would get microtime now

explode benchmark results:

name                old time/op    new time/op    delta
ExplodeToArray      416ns ± 0%     408ns ± 0%   -1.95%  (p=0.000 n=9+9)
ExplodeNth          450ns ± 1%     153ns ± 0%  -66.00%  (p=0.000 n=10+7)
Explode1            457ns ± 1%     143ns ± 1%  -68.78%  (p=0.000 n=10+10)
Explode2            504ns ± 2%     276ns ± 1%  -45.32%  (p=0.000 n=10+10)
Explode3            913ns ± 1%     427ns ± 0%  -53.28%  (p=0.000 n=10+8)
Explode4            951ns ± 1%     564ns ± 0%  -40.69%  (p=0.000 n=10+10)
Explode3discard     866ns ± 2%     290ns ± 1%  -66.46%  (p=0.000 n=9+10)
Explode2limit       479ns ± 1%     297ns ± 1%  -38.12%  (p=0.000 n=10+10)
Explode3limit       835ns ± 2%     471ns ± 0%  -43.54%  (p=0.000 n=8+9)
Explode4limit       918ns ± 2%     609ns ± 2%  -33.64%  (p=0.000 n=10+10)
[Geo mean]          642ns          329ns       -48.85%

name                      old alloc/op   new alloc/op   delta
ExplodeToArray       344B ± 0%      344B ± 0%        ~  (all equal)
ExplodeNth           344B ± 0%       40B ± 0%  -88.37%  (p=0.000 n=10+10)
Explode1             344B ± 0%       40B ± 0%  -88.37%  (p=0.000 n=10+10)
Explode2             344B ± 0%       80B ± 0%  -76.74%  (p=0.000 n=10+10)
Explode3             688B ± 0%      112B ± 0%  -83.72%  (p=0.000 n=10+10)
Explode4             688B ± 0%      160B ± 0%  -76.74%  (p=0.000 n=10+10)
Explode3discard      688B ± 0%       56B ± 0%  -91.86%  (p=0.000 n=10+10)
Explode2limit        352B ± 0%       80B ± 0%  -77.27%  (p=0.000 n=10+10)
Explode3limit        592B ± 0%      112B ± 0%  -81.08%  (p=0.000 n=10+10)
Explode4limit        624B ± 0%      160B ± 0%  -74.36%  (p=0.000 n=10+10)
[Geo mean]           476B            96B       -79.92%

name                 old allocs/op  new allocs/op  delta
ExplodeToArray       9.00 ± 0%      9.00 ± 0%        ~  (all equal)
ExplodeNth           9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
Explode1             9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
Explode2             9.00 ± 0%      4.00 ± 0%  -55.56%  (p=0.000 n=10+10)
Explode3             17.0 ± 0%       6.0 ± 0%  -64.71%  (p=0.000 n=10+10)
Explode4             17.0 ± 0%       8.0 ± 0%  -52.94%  (p=0.000 n=10+10)
Explode3discard      17.0 ± 0%       3.0 ± 0%  -82.35%  (p=0.000 n=10+10)
Explode2limit        9.00 ± 0%      4.00 ± 0%  -55.56%  (p=0.000 n=10+10)
Explode3limit        15.0 ± 0%       6.0 ± 0%  -60.00%  (p=0.000 n=10+10)
Explode4limit        16.0 ± 0%       8.0 ± 0%  -50.00%  (p=0.000 n=10+10)
[Geo mean]           12.1            4.6       -62.35%

substr/trim benchmark results:

name                          old time/op    new time/op    delta
TmpString::IntvalSubstr          137ns ± 1%      90ns ± 0%   -34.43%  (p=0.000 n=8+10)
TmpString::AppendSubstr          185ns ± 2%     131ns ± 2%   -29.42%  (p=0.000 n=9+9)
TmpString::Concat2               149ns ± 1%      91ns ± 1%   -38.94%  (p=0.000 n=10+9)
TmpString::Concat3               263ns ± 1%     152ns ± 1%   -42.29%  (p=0.000 n=10+8)
TmpString::ConcatSubstrConv      112ns ± 1%      75ns ± 6%   -33.10%  (p=0.000 n=9+10)
TmpString::Substr3               179ns ± 0%      91ns ± 0%   -49.08%  (p=0.000 n=10+8)
TmpString::IndexTrimSubstr       203ns ± 2%     144ns ± 1%   -29.20%  (p=0.000 n=10+10)
TmpString::IndexSubstr           488ns ± 0%     376ns ± 0%   -22.85%  (p=0.000 n=9+10)
TmpString::TrimSubstrA           150ns ± 1%     122ns ± 0%   -18.60%  (p=0.000 n=10+8)
TmpString::TrimSubstrB           152ns ± 1%     121ns ± 1%   -20.60%  (p=0.000 n=10+10)
TmpString::TrimSubstrC           117ns ± 3%     117ns ± 0%         ~  (p=0.015 n=10+8)
TmpString::SubstrBoolContext    53.5ns ± 3%    28.0ns ± 0%   -47.66%  (p=0.000 n=10+9)
TmpString::TrimBoolContext       198ns ± 1%     127ns ± 0%   -35.97%  (p=0.000 n=9+8)
[Geo mean]                       163ns          110ns        -32.14%

name                          old alloc/op   new alloc/op   delta
TmpString::IntvalSubstr          48.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::AppendSubstr           160B ± 0%       96B ± 0%   -40.00%  (p=0.000 n=10+10)
TmpString::Concat2                104B ± 0%       40B ± 0%   -61.54%  (p=0.000 n=10+10)
TmpString::Concat3                152B ± 0%       56B ± 0%   -63.16%  (p=0.000 n=10+10)
TmpString::ConcatSubstrConv       104B ± 0%       56B ± 0%   -46.15%  (p=0.000 n=10+10)
TmpString::Substr3               80.0B ± 0%     24.0B ± 0%   -70.00%  (p=0.000 n=10+10)
TmpString::IndexTrimSubstr       56.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::IndexSubstr           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrA           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrB           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrC           32.0B ± 0%     32.0B ± 0%         ~  (all equal)
TmpString::SubstrBoolContext     24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::TrimBoolContext       64.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name                          old allocs/op  new allocs/op  delta
TmpString::IntvalSubstr           2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::AppendSubstr           4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::Concat2                3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)
TmpString::Concat3                4.00 ± 0%      1.00 ± 0%   -75.00%  (p=0.000 n=10+10)
TmpString::ConcatSubstrConv       2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::Substr3                3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)
TmpString::IndexTrimSubstr        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::IndexSubstr            4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrA            2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrB            2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrC            1.00 ± 0%      1.00 ± 0%         ~  (all equal)
TmpString::SubstrBoolContext      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::TrimBoolContext        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

string conversion benchmark results:

name                                  old time/op    new time/op    delta
Strconv::ConcatEmptyAndInt32small       44.0ns ± 0%    14.0ns ± 0%   -68.18%  (p=0.002 n=8+10)
Strconv::ConcatEmptyAndMixed            61.4ns ± 1%    13.0ns ± 0%   -78.83%  (p=0.000 n=10+9)
Strconv::StringBuildSingleInt32small    43.3ns ± 2%    14.0ns ± 0%   -67.67%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed         59.0ns ± 0%    12.0ns ± 0%   -79.66%  (p=0.000 n=10+10)
Strconv::ConcatOperand                   115ns ± 1%      72ns ± 1%   -37.02%  (p=0.000 n=10+10)
[Geo mean]                              60.2ns         23.9ns        -60.29%

name                                  old alloc/op   new alloc/op   delta
Strconv::ConcatEmptyAndInt32small        40.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatEmptyAndMixed             24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleInt32small     40.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed          24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatOperand                   56.0B ± 0%     40.0B ± 0%   -28.57%  (p=0.000 n=10+10)

name                                  old allocs/op  new allocs/op  delta
Strconv::ConcatEmptyAndInt32small         1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatEmptyAndMixed              1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleInt32small      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed           1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatOperand                    2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
                                
Created at 1 day ago

commit forgotten build 4 assets

build 5

Probably the last one before the game jam deadline.

Bug fixes: -- Second checkmark near the bonus levels (if they were completed and moved from the story levels) Content modifications: -- A "switch" level now modifies words longer than 5 too -- Done some more manual pages proof reading

Created at 1 day ago

Update template_engines.md

Created at 2 days ago

Update template_engines.md

Created at 2 days ago

remove unused NullDataProvider

Created at 2 days ago
delete branch
quasilyte delete branch quasilyte/jit_on2
Created at 2 days ago

opcache.jit=on looks like to be a better default (#43)

Created at 2 days ago
pull request closed
`opcache.jit=on` looks like to be a better default
Created at 2 days ago
pull request opened
`opcache.jit=on` looks like to be a better default
Created at 2 days ago
create branch
quasilyte create branch quasilyte/jit_on2
Created at 2 days ago
delete branch
quasilyte delete branch quasilyte/use_more_agressive_phpjit
Created at 2 days ago

enable all optimizations from the PHP JIT (#42)

Created at 2 days ago
pull request closed
enable all optimizations from the PHP JIT
Created at 2 days ago
pull request opened
enable all optimizations from the PHP JIT
Created at 2 days ago
create branch
quasilyte create branch quasilyte/use_more_agressive_phpjit
Created at 2 days ago

add compiler benchmarks

Created at 2 days ago

make test signatures compatible with phpunit

Created at 2 days ago

fix lexer handling of { inside the text blocks

docs: make ktemplate example more precise

Merge branch 'master' of https://github.com/quasilyte/KTemplate

Created at 2 days ago

Update README.md

Created at 2 days ago

Create template_engines.md

Created at 2 days ago

build 4

Other: -- Made sound levels configurable Content modifications: -- Rebalanced some levels New content: -- Added a conditions vocab manual page -- Added a "binary tree" level -- Added a "conveyor" level

Created at 2 days ago

make audio group levels configurable

Created at 2 days ago
push

eliminate deprecated malloc hooks (#669)

  • eliminate deprecated malloc hooks

  • extend tests

added all changes and new features to documentation for Nov 2022 (#657)

fixed declare int_entries with 0 size for gcc version >= 10 (#672)

[runtime] add runtime configuration support (#667)

Add the ability to specify a json-config as a server argument to be used inside the script with 'kphp_get_runtime_config()'.

Fix unexpected memory piece error (#668)

Most likely, the key reason of the error - malloc replacement isn't rolled back correctly sometimes. In production it happens in 2 cases: at qmem_clear function on runtime environment freeing and at rpcx_execute on receiving RPC response. Now we force malloc rollback in this 2 cases to fix the error itself and then report the critical error with the stacktrace of last malloc replacement to be able to investigate it more precisely.

relates to KPHP-1511

[runtime] fix sigsegv in script initialization(#671)

support build under ubuntu 22 (#673)

  • fix build: pthread

  • fix build: stacksize

  • fix build: suppress openssl's deprecated declarations warnings; fix const-correctness

  • fix build: signature discrepancy

  • fix build: link both ssl and crypto statically

add ctype family of functions (#654)

  • implement ctype family of functions

  • enable ctype-related tests from zend repo

implement bcsqrt function (#659)

  • implement bcsqrt()

add support of floating numbers in bcmod() (#663)

replaced sprintf to snprintf (#670)

replaced deprecated sprintf to snprintf

add floating numbers in bcpow() (#665)

  • add support of $scale=null

  • permit floating args and negative exponent in bcpow()

Final improvements in Modulite support before the first public release (#674)

  1. Collect classes from .modulite.yaml files Now, .modulite.yaml files are parsed in collect-required pass, and they are also used to discover classes.

  2. env KPHP_MODULITE_ENABLED = 0|1|2 0 — modulites disabled 1 — modulites enabled, wrong code gives a compilation error 2 — modulites enabled, wrong code just outputs notices to console

  3. Small changes in error messages and tests Keep naming in sync with modulte-phpstan plugin that is prepared to be released to support regular PHP projects

add DateInterval (#652)

  • implement DateInterval class

  • implement DateTime's add/sub/diff methods

fixed memcpy call from simd-int-to-string and buffer size for uint64 (#678)

[tests] install engines deb packages instead of building them from sources for integration tests (#685)

[vkext] Fix RPC TL Maybe<array> storing (#683)

In typed serialization mode TL type Maybe %(Vector string) corresponds PHP type string[]|null. But if you tried to store ["asdf", "asdf"], you would get the following error: "Unknown constructor asdf for type Maybe" So it mistakenly was expected to be like in untyped mode, i.e.: ["_" => "resultTrue", "result" => ["asdf", "asdf"]].

It happened because typed mode was determined by the condition like type of serialized object is not array in case of Maybe storing. But this condition is not hold in case of Maybe<Vector> or Maybe<Tuple>.

Now we will use special typed_mode flag to distinguish typed and untyped storing mode. We will set it at every typed storing entrypoint and reset after that.

Fix malloc replacement error (#682)

"Unexpected memory piece" error happens because script allocator tries to deallocate some memory pieces allocated from heap by system allocator before. It happens because timeout signal is raised when malloc is replaced with script allocator and then shutdown functions are called with replaced malloc. Here are enhancements preventing this behavior:

  • Forcibly rollback malloc replacement if any script error occurs (timeout as well)
  • Add last malloc replacement stacktrace to unexpected memory piece error. It will help to solve such problems in the future

[compiler] add optimization rules

Related changes:

  • made hrtime_int and other specialized function internal
  • moved hrtime and microtime replacement to the rewrite rules
  • introduced a tmp_string concept
  • added a string::append(tmp_string) overloading
  • added wrap_substr_args to re-use substr start+length handling (it's weird)
  • added new kphp phpdoc tags for internal use
  • restriction-isset learned how to check the optimized functions
  • added explode specializations that return tuples, etc
  • added internal functions aliases if they're replacing existing functions
    • for example, instead of microtime_string the user would get microtime now

explode benchmark results:

name                old time/op    new time/op    delta
ExplodeToArray      416ns ± 0%     408ns ± 0%   -1.95%  (p=0.000 n=9+9)
ExplodeNth          450ns ± 1%     153ns ± 0%  -66.00%  (p=0.000 n=10+7)
Explode1            457ns ± 1%     143ns ± 1%  -68.78%  (p=0.000 n=10+10)
Explode2            504ns ± 2%     276ns ± 1%  -45.32%  (p=0.000 n=10+10)
Explode3            913ns ± 1%     427ns ± 0%  -53.28%  (p=0.000 n=10+8)
Explode4            951ns ± 1%     564ns ± 0%  -40.69%  (p=0.000 n=10+10)
Explode3discard     866ns ± 2%     290ns ± 1%  -66.46%  (p=0.000 n=9+10)
Explode2limit       479ns ± 1%     297ns ± 1%  -38.12%  (p=0.000 n=10+10)
Explode3limit       835ns ± 2%     471ns ± 0%  -43.54%  (p=0.000 n=8+9)
Explode4limit       918ns ± 2%     609ns ± 2%  -33.64%  (p=0.000 n=10+10)
[Geo mean]          642ns          329ns       -48.85%

name                      old alloc/op   new alloc/op   delta
ExplodeToArray       344B ± 0%      344B ± 0%        ~  (all equal)
ExplodeNth           344B ± 0%       40B ± 0%  -88.37%  (p=0.000 n=10+10)
Explode1             344B ± 0%       40B ± 0%  -88.37%  (p=0.000 n=10+10)
Explode2             344B ± 0%       80B ± 0%  -76.74%  (p=0.000 n=10+10)
Explode3             688B ± 0%      112B ± 0%  -83.72%  (p=0.000 n=10+10)
Explode4             688B ± 0%      160B ± 0%  -76.74%  (p=0.000 n=10+10)
Explode3discard      688B ± 0%       56B ± 0%  -91.86%  (p=0.000 n=10+10)
Explode2limit        352B ± 0%       80B ± 0%  -77.27%  (p=0.000 n=10+10)
Explode3limit        592B ± 0%      112B ± 0%  -81.08%  (p=0.000 n=10+10)
Explode4limit        624B ± 0%      160B ± 0%  -74.36%  (p=0.000 n=10+10)
[Geo mean]           476B            96B       -79.92%

name                 old allocs/op  new allocs/op  delta
ExplodeToArray       9.00 ± 0%      9.00 ± 0%        ~  (all equal)
ExplodeNth           9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
Explode1             9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
Explode2             9.00 ± 0%      4.00 ± 0%  -55.56%  (p=0.000 n=10+10)
Explode3             17.0 ± 0%       6.0 ± 0%  -64.71%  (p=0.000 n=10+10)
Explode4             17.0 ± 0%       8.0 ± 0%  -52.94%  (p=0.000 n=10+10)
Explode3discard      17.0 ± 0%       3.0 ± 0%  -82.35%  (p=0.000 n=10+10)
Explode2limit        9.00 ± 0%      4.00 ± 0%  -55.56%  (p=0.000 n=10+10)
Explode3limit        15.0 ± 0%       6.0 ± 0%  -60.00%  (p=0.000 n=10+10)
Explode4limit        16.0 ± 0%       8.0 ± 0%  -50.00%  (p=0.000 n=10+10)
[Geo mean]           12.1            4.6       -62.35%

substr/trim benchmark results:

name                          old time/op    new time/op    delta
TmpString::IntvalSubstr          137ns ± 1%      90ns ± 0%   -34.43%  (p=0.000 n=8+10)
TmpString::AppendSubstr          185ns ± 2%     131ns ± 2%   -29.42%  (p=0.000 n=9+9)
TmpString::Concat2               149ns ± 1%      91ns ± 1%   -38.94%  (p=0.000 n=10+9)
TmpString::Concat3               263ns ± 1%     152ns ± 1%   -42.29%  (p=0.000 n=10+8)
TmpString::ConcatSubstrConv      112ns ± 1%      75ns ± 6%   -33.10%  (p=0.000 n=9+10)
TmpString::Substr3               179ns ± 0%      91ns ± 0%   -49.08%  (p=0.000 n=10+8)
TmpString::IndexTrimSubstr       203ns ± 2%     144ns ± 1%   -29.20%  (p=0.000 n=10+10)
TmpString::IndexSubstr           488ns ± 0%     376ns ± 0%   -22.85%  (p=0.000 n=9+10)
TmpString::TrimSubstrA           150ns ± 1%     122ns ± 0%   -18.60%  (p=0.000 n=10+8)
TmpString::TrimSubstrB           152ns ± 1%     121ns ± 1%   -20.60%  (p=0.000 n=10+10)
TmpString::TrimSubstrC           117ns ± 3%     117ns ± 0%         ~  (p=0.015 n=10+8)
TmpString::SubstrBoolContext    53.5ns ± 3%    28.0ns ± 0%   -47.66%  (p=0.000 n=10+9)
TmpString::TrimBoolContext       198ns ± 1%     127ns ± 0%   -35.97%  (p=0.000 n=9+8)
[Geo mean]                       163ns          110ns        -32.14%

name                          old alloc/op   new alloc/op   delta
TmpString::IntvalSubstr          48.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::AppendSubstr           160B ± 0%       96B ± 0%   -40.00%  (p=0.000 n=10+10)
TmpString::Concat2                104B ± 0%       40B ± 0%   -61.54%  (p=0.000 n=10+10)
TmpString::Concat3                152B ± 0%       56B ± 0%   -63.16%  (p=0.000 n=10+10)
TmpString::ConcatSubstrConv       104B ± 0%       56B ± 0%   -46.15%  (p=0.000 n=10+10)
TmpString::Substr3               80.0B ± 0%     24.0B ± 0%   -70.00%  (p=0.000 n=10+10)
TmpString::IndexTrimSubstr       56.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::IndexSubstr           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrA           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrB           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrC           32.0B ± 0%     32.0B ± 0%         ~  (all equal)
TmpString::SubstrBoolContext     24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::TrimBoolContext       64.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name                          old allocs/op  new allocs/op  delta
TmpString::IntvalSubstr           2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::AppendSubstr           4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::Concat2                3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)
TmpString::Concat3                4.00 ± 0%      1.00 ± 0%   -75.00%  (p=0.000 n=10+10)
TmpString::ConcatSubstrConv       2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::Substr3                3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)
TmpString::IndexTrimSubstr        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::IndexSubstr            4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrA            2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrB            2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrC            1.00 ± 0%      1.00 ± 0%         ~  (all equal)
TmpString::SubstrBoolContext      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::TrimBoolContext        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

string conversion benchmark results:

name                                  old time/op    new time/op    delta
Strconv::ConcatEmptyAndInt32small       44.0ns ± 0%    14.0ns ± 0%   -68.18%  (p=0.002 n=8+10)
Strconv::ConcatEmptyAndMixed            61.4ns ± 1%    13.0ns ± 0%   -78.83%  (p=0.000 n=10+9)
Strconv::StringBuildSingleInt32small    43.3ns ± 2%    14.0ns ± 0%   -67.67%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed         59.0ns ± 0%    12.0ns ± 0%   -79.66%  (p=0.000 n=10+10)
Strconv::ConcatOperand                   115ns ± 1%      72ns ± 1%   -37.02%  (p=0.000 n=10+10)
[Geo mean]                              60.2ns         23.9ns        -60.29%

name                                  old alloc/op   new alloc/op   delta
Strconv::ConcatEmptyAndInt32small        40.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatEmptyAndMixed             24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleInt32small     40.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed          24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatOperand                   56.0B ± 0%     40.0B ± 0%   -28.57%  (p=0.000 n=10+10)

name                                  old allocs/op  new allocs/op  delta
Strconv::ConcatEmptyAndInt32small         1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatEmptyAndMixed              1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleInt32small      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed           1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatOperand                    2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
                                
Created at 3 days ago
push

[compiler] add optimization rules

Related changes:

  • made hrtime_int and other specialized function internal
  • moved hrtime and microtime replacement to the rewrite rules
  • introduced a tmp_string concept
  • added a string::append(tmp_string) overloading
  • added wrap_substr_args to re-use substr start+length handling (it's weird)
  • added new kphp phpdoc tags for internal use
  • restriction-isset learned how to check the optimized functions
  • added explode specializations that return tuples, etc
  • added internal functions aliases if they're replacing existing functions
    • for example, instead of microtime_string the user would get microtime now

explode benchmark results:

name                old time/op    new time/op    delta
ExplodeToArray      416ns ± 0%     408ns ± 0%   -1.95%  (p=0.000 n=9+9)
ExplodeNth          450ns ± 1%     153ns ± 0%  -66.00%  (p=0.000 n=10+7)
Explode1            457ns ± 1%     143ns ± 1%  -68.78%  (p=0.000 n=10+10)
Explode2            504ns ± 2%     276ns ± 1%  -45.32%  (p=0.000 n=10+10)
Explode3            913ns ± 1%     427ns ± 0%  -53.28%  (p=0.000 n=10+8)
Explode4            951ns ± 1%     564ns ± 0%  -40.69%  (p=0.000 n=10+10)
Explode3discard     866ns ± 2%     290ns ± 1%  -66.46%  (p=0.000 n=9+10)
Explode2limit       479ns ± 1%     297ns ± 1%  -38.12%  (p=0.000 n=10+10)
Explode3limit       835ns ± 2%     471ns ± 0%  -43.54%  (p=0.000 n=8+9)
Explode4limit       918ns ± 2%     609ns ± 2%  -33.64%  (p=0.000 n=10+10)
[Geo mean]          642ns          329ns       -48.85%

name                      old alloc/op   new alloc/op   delta
ExplodeToArray       344B ± 0%      344B ± 0%        ~  (all equal)
ExplodeNth           344B ± 0%       40B ± 0%  -88.37%  (p=0.000 n=10+10)
Explode1             344B ± 0%       40B ± 0%  -88.37%  (p=0.000 n=10+10)
Explode2             344B ± 0%       80B ± 0%  -76.74%  (p=0.000 n=10+10)
Explode3             688B ± 0%      112B ± 0%  -83.72%  (p=0.000 n=10+10)
Explode4             688B ± 0%      160B ± 0%  -76.74%  (p=0.000 n=10+10)
Explode3discard      688B ± 0%       56B ± 0%  -91.86%  (p=0.000 n=10+10)
Explode2limit        352B ± 0%       80B ± 0%  -77.27%  (p=0.000 n=10+10)
Explode3limit        592B ± 0%      112B ± 0%  -81.08%  (p=0.000 n=10+10)
Explode4limit        624B ± 0%      160B ± 0%  -74.36%  (p=0.000 n=10+10)
[Geo mean]           476B            96B       -79.92%

name                 old allocs/op  new allocs/op  delta
ExplodeToArray       9.00 ± 0%      9.00 ± 0%        ~  (all equal)
ExplodeNth           9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
Explode1             9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
Explode2             9.00 ± 0%      4.00 ± 0%  -55.56%  (p=0.000 n=10+10)
Explode3             17.0 ± 0%       6.0 ± 0%  -64.71%  (p=0.000 n=10+10)
Explode4             17.0 ± 0%       8.0 ± 0%  -52.94%  (p=0.000 n=10+10)
Explode3discard      17.0 ± 0%       3.0 ± 0%  -82.35%  (p=0.000 n=10+10)
Explode2limit        9.00 ± 0%      4.00 ± 0%  -55.56%  (p=0.000 n=10+10)
Explode3limit        15.0 ± 0%       6.0 ± 0%  -60.00%  (p=0.000 n=10+10)
Explode4limit        16.0 ± 0%       8.0 ± 0%  -50.00%  (p=0.000 n=10+10)
[Geo mean]           12.1            4.6       -62.35%

substr/trim benchmark results:

name                          old time/op    new time/op    delta
TmpString::IntvalSubstr          137ns ± 1%      90ns ± 0%   -34.43%  (p=0.000 n=8+10)
TmpString::AppendSubstr          185ns ± 2%     131ns ± 2%   -29.42%  (p=0.000 n=9+9)
TmpString::Concat2               149ns ± 1%      91ns ± 1%   -38.94%  (p=0.000 n=10+9)
TmpString::Concat3               263ns ± 1%     152ns ± 1%   -42.29%  (p=0.000 n=10+8)
TmpString::ConcatSubstrConv      112ns ± 1%      75ns ± 6%   -33.10%  (p=0.000 n=9+10)
TmpString::Substr3               179ns ± 0%      91ns ± 0%   -49.08%  (p=0.000 n=10+8)
TmpString::IndexTrimSubstr       203ns ± 2%     144ns ± 1%   -29.20%  (p=0.000 n=10+10)
TmpString::IndexSubstr           488ns ± 0%     376ns ± 0%   -22.85%  (p=0.000 n=9+10)
TmpString::TrimSubstrA           150ns ± 1%     122ns ± 0%   -18.60%  (p=0.000 n=10+8)
TmpString::TrimSubstrB           152ns ± 1%     121ns ± 1%   -20.60%  (p=0.000 n=10+10)
TmpString::TrimSubstrC           117ns ± 3%     117ns ± 0%         ~  (p=0.015 n=10+8)
TmpString::SubstrBoolContext    53.5ns ± 3%    28.0ns ± 0%   -47.66%  (p=0.000 n=10+9)
TmpString::TrimBoolContext       198ns ± 1%     127ns ± 0%   -35.97%  (p=0.000 n=9+8)
[Geo mean]                       163ns          110ns        -32.14%

name                          old alloc/op   new alloc/op   delta
TmpString::IntvalSubstr          48.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::AppendSubstr           160B ± 0%       96B ± 0%   -40.00%  (p=0.000 n=10+10)
TmpString::Concat2                104B ± 0%       40B ± 0%   -61.54%  (p=0.000 n=10+10)
TmpString::Concat3                152B ± 0%       56B ± 0%   -63.16%  (p=0.000 n=10+10)
TmpString::ConcatSubstrConv       104B ± 0%       56B ± 0%   -46.15%  (p=0.000 n=10+10)
TmpString::Substr3               80.0B ± 0%     24.0B ± 0%   -70.00%  (p=0.000 n=10+10)
TmpString::IndexTrimSubstr       56.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::IndexSubstr           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrA           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrB           64.0B ± 0%     32.0B ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrC           32.0B ± 0%     32.0B ± 0%         ~  (all equal)
TmpString::SubstrBoolContext     24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
TmpString::TrimBoolContext       64.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name                          old allocs/op  new allocs/op  delta
TmpString::IntvalSubstr           2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::AppendSubstr           4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::Concat2                3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)
TmpString::Concat3                4.00 ± 0%      1.00 ± 0%   -75.00%  (p=0.000 n=10+10)
TmpString::ConcatSubstrConv       2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::Substr3                3.00 ± 0%      1.00 ± 0%   -66.67%  (p=0.000 n=10+10)
TmpString::IndexTrimSubstr        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::IndexSubstr            4.00 ± 0%      2.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrA            2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrB            2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
TmpString::TrimSubstrC            1.00 ± 0%      1.00 ± 0%         ~  (all equal)
TmpString::SubstrBoolContext      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
TmpString::TrimBoolContext        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

string conversion benchmark results:

name                                  old time/op    new time/op    delta
Strconv::ConcatEmptyAndInt32small       44.0ns ± 0%    14.0ns ± 0%   -68.18%  (p=0.002 n=8+10)
Strconv::ConcatEmptyAndMixed            61.4ns ± 1%    13.0ns ± 0%   -78.83%  (p=0.000 n=10+9)
Strconv::StringBuildSingleInt32small    43.3ns ± 2%    14.0ns ± 0%   -67.67%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed         59.0ns ± 0%    12.0ns ± 0%   -79.66%  (p=0.000 n=10+10)
Strconv::ConcatOperand                   115ns ± 1%      72ns ± 1%   -37.02%  (p=0.000 n=10+10)
[Geo mean]                              60.2ns         23.9ns        -60.29%

name                                  old alloc/op   new alloc/op   delta
Strconv::ConcatEmptyAndInt32small        40.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatEmptyAndMixed             24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleInt32small     40.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed          24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatOperand                   56.0B ± 0%     40.0B ± 0%   -28.57%  (p=0.000 n=10+10)

name                                  old allocs/op  new allocs/op  delta
Strconv::ConcatEmptyAndInt32small         1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatEmptyAndMixed              1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleInt32small      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::StringBuildSingleMixed           1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Strconv::ConcatOperand                    2.00 ± 0%      1.00 ± 0%   -50.00%  (p=0.000 n=10+10)
                                
Created at 3 days ago