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

More performance improvements #4210

Merged
merged 48 commits into from
Mar 29, 2023
Merged

More performance improvements #4210

merged 48 commits into from
Mar 29, 2023

Conversation

jimidle
Copy link
Collaborator

@jimidle jimidle commented Mar 28, 2023

Fix: Performance improvements for hashtable stuff and cache and fix to comparator

A lot of small changes in this one. Even though some of the commits look massive, they are all just
type changes from interface to struct pointers and similar things. They are all interrelated and cannot be separated
out.

This gets the Go runtime faster than Java on good grammars and within shouting distance on the terrible ones such as the MySql grammar. I am going to submit some improvements for those terrible grammars but my next task is memory pools for structs and related things that will have a big effect on these crummy grammars. This change gives me these results on my Mac for the MySql grammar:

Warmup run

Input Elapsed parse time
analyze.sql 30.009214ms
bitrix_queries_cut.sql 123.628673491s
bitrix_queries_cut_small.sql 20.716369ms
case_sensitive_sql.sql 254.319312ms
ddl_alter.sql 257.266811ms
ddl_create.sql 4.042047644s
ddl_drop.sql 29.592294ms
ddl_flush.sql 13.866632ms
dml_delete.sql 188.947062ms
dml_insert.sql 1.054598045s
dml_replace.sql 103.230765ms
dml_select.sql 7.639615925s
dml_test_arithmetic_expression.sql 2.706622ms
dml_union.sql 205.721784ms
dml_update.sql 380.629755ms
dml_with.sql 81.843553ms
ext_tests.sql 1.329152887s
grant.sql 32.514802ms
kill.sql 8.69661ms
mysql_spec_comment.sql 52.157974ms
optimize.sql 3.617809ms
smoke_tests.sql 727.123175ms

Elapsed time (0): 1m40.088535933s

Performance round # 1

Input Elapsed parse time
analyze.sql 5.172696ms
bitrix_queries_cut.sql 1m7.660708623s
bitrix_queries_cut_small.sql 20.4306ms
case_sensitive_sql.sql 108.66277ms
ddl_alter.sql 123.031896ms
ddl_create.sql 2.609207692s
ddl_drop.sql 26.253661ms
ddl_flush.sql 7.472161ms
dml_delete.sql 73.716928ms
dml_insert.sql 680.593347ms
dml_replace.sql 19.693085ms
dml_select.sql 4.64892433s
dml_test_arithmetic_expression.sql 1.329277ms
dml_union.sql 155.79117ms
dml_update.sql 232.733093ms
dml_with.sql 78.77783ms
ext_tests.sql 779.118564ms
grant.sql 14.549089ms
kill.sql 2.639832ms
mysql_spec_comment.sql 50.64345ms
optimize.sql 3.646558ms
smoke_tests.sql 743.777079ms

Elapsed time (1): 1m18.048023031s|

The bitrix_queries_cut.sql is still quite poor compared to Java. Its because the big input file causes gobs of allocations in both Java and Go. My memory changes will greatly affect these times.

@parrt PLease merge this when you can as I need these changes to make my memory pool changes. I will do some fancy branching and rebasing to deal with it until you can merge for me.

@kaby76 - you should find this is now runnable on your system. All benchmarks that are SLL or half decent grammars should really be very fast. There was an issue filed a while back with test source. The reporter wanted 0.2 seconds but we are now very very much faster than that with the go runtime.

parrt and others added 30 commits March 28, 2023 16:17
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
undefined

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Eric Vergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Posix threads are available only on Unix (and unix like) platforms.
Wrap the dependency accordingly so builds don't fail on other platforms.

Signed-off-by: HS <hs@apotell.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>
… in to the root (pre v4) files (antlr#4154)

- Incorporate an interative tree walker
 - Expose Reset() and String() in lexer/token and add test

Signed-off-by: Jim.Idle <jimi@idle.ws>
* feat: Remove the old version of the source code, as at v4.x.y the source must be under /v4 for modules

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: tidy up old version of go.mod (non v4 version), which is now deprecated

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
The badge in the README suggests that ANTLR requires Java 7 or higher,
whereas since ANTLR v4.10 Java 11 or higher is required.

Signed-off-by: Robert Adam <dev@robert-adam.de>
(cherry picked from commit 8188dc5)
Signed-off-by: Jim.Idle <jimi@idle.ws>
…BUILD_CPP_TESTS is not set (antlr#4121)

Signed-off-by: Leonardo Sarmiento <leonardo@moduleworks.com>
Co-authored-by: Leonardo Sarmiento <leonardo@moduleworks.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>
* Cpp: Remove code duplication

The same function was defined inside multiple different source files (in
an anonymous namespace).
Not only is this generally bad practice from a maintenance point of
view, but it also break unity builds (which can speed up compilation
times A LOT).

The fix simply consists in introducing a new Utils file that contains
the single implementation and every source file that uses this function
simply has to be linked against that new file (and include the
corresponding header).

Signed-off-by: Robert Adam <dev@robert-adam.de>

* CI: Enable unity builds for cpp targets

This should reduce the build time for those steps significantly

Note: Unity builds are enabled only for cmake-based CI builds

Signed-off-by: Robert Adam <dev@robert-adam.de>

* CI: Perform unity and non-unity cpp builds

Signed-off-by: Robert Adam <dev@robert-adam.de>

---------

Signed-off-by: Robert Adam <dev@robert-adam.de>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>
…4 off the replace option on the go.mod file (antlr#4163)

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
…lashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>
* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>
…ntlr#4169)

* doc: Updates to some of the Go doc comments to start a ful ldocumentation cleanup

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes.

Using this as a method of forcing myself to read every line of code in the runtime, and therefore
discover mistakes in the original implementation. And, of course, actually working docs for the
Go runtime, can only be a good thing.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes

Also changes the exporet level of a some variables and funcs that were not correct,
even though no user has currently needed them it would seem.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Many updates to document exported fuctions correctly and reformat the ingerited Java code

It looks like a massive amount of changes, but it is almost all doc or changing exports or renaming
unused paramters etc to make the Go linter happy.

No actual code changes yet.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More additions and corrections to the Go documentation for the runtime

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Final clean of exported func and type documentation

There will be more to do here as there are a lot of things that are hidden internal to the antlr
package that probably should not be. There are also a lot of exported funcs and types without
any documentation, that will eventually need to be cleaned up.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Changed Parser typings (antlr#4149)

Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file (antlr#4163)

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Feature/gotestfix (antlr#4168)

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <frank.josua@gmail.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>
* feat: Createa n Init routine for BaseATNConfig so we can embed sructs rather than allocate to pointers

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change BaseATNConfig to be properly embedded in other structs such as LexerATNConfig instead of by pointer

This is the first of many changes that switches the embedded class structure that was copying
Java class hieracrchy from allocations/new to proper embedding such that any struct is
allocated with one allocation not two or more. Main PR will cover what this means.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change embedding for ATNBaseSimulator to true embedding instaed of pointer

Saves an extra allocation and helps the GC

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Switch the use of pointers to embedded ATN states to true embeddding

Saves many allocations and grbage collections

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Correct the way that PredictionContext is compared for merge

Should reduce allocation count by tons.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Feature/docclean Greatly improve the godoc comments in the runtime (antlr#4169)

* doc: Updates to some of the Go doc comments to start a ful ldocumentation cleanup

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes.

Using this as a method of forcing myself to read every line of code in the runtime, and therefore
discover mistakes in the original implementation. And, of course, actually working docs for the
Go runtime, can only be a good thing.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes

Also changes the exporet level of a some variables and funcs that were not correct,
even though no user has currently needed them it would seem.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Many updates to document exported fuctions correctly and reformat the ingerited Java code

It looks like a massive amount of changes, but it is almost all doc or changing exports or renaming
unused paramters etc to make the Go linter happy.

No actual code changes yet.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More additions and corrections to the Go documentation for the runtime

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Final clean of exported func and type documentation

There will be more to do here as there are a lot of things that are hidden internal to the antlr
package that probably should not be. There are also a lot of exported funcs and types without
any documentation, that will eventually need to be cleaned up.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Changed Parser typings (antlr#4149)

Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file (antlr#4163)

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Feature/gotestfix (antlr#4168)

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <frank.josua@gmail.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>

* feat: Change BaseATNConfig to be properly embedded in other structs such as LexerATNConfig instead of by pointer

This is the first of many changes that switches the embedded class structure that was copying
Java class hieracrchy from allocations/new to proper embedding such that any struct is
allocated with one allocation not two or more. Main PR will cover what this means.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change embedding for ATNBaseSimulator to true embedding instaed of pointer

Saves an extra allocation and helps the GC

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Correct the way that PredictionContext is compared for merge

Should reduce allocation count by tons.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Merge documentation updates

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Rework predictions tructs to use emedding instead of pointers

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: more reworking of PredictionContext for embedding

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Ensure that EmptyPredictionContext is correctly initialized

Rework of the variaous PredictionContexts has reduced memory allocations to between
30% and 50% of previous version.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change from use of type casting to using stored type

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Convert CommonToken to true emedding rather than pointers

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <frank.josua@gmail.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Eric Vergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>
…omparing two pointers!

Fixes: antlr#3967
Closes antlr#3967

 - A small error was made whereby the comparison with a newly created merge `M` of two prediction contexts
  `a` and `b`, was comparing the pointers of `a` and `M` and not using the internal Equals() method.
  The ATN output trace is now equal.

 - Also adds a new testrig internal project (so it won't be used by `go get`) that allows quick setup
   and testing of ATN tracing for a test grammar and test input.

 - Excludes go performance profiles from git

 - Corrects a small error in one of the ATN tracing scripts.

Signed-off-by: Jim.Idle <jimi@idle.ws>
… fixed

Signed-off-by: Jim.Idle <jimi@idle.ws>
 - I missed this on my first evaluation of all the collections used
   by the code I inherited. The PredictionCache was implemented as a
   map using PredictionContext pointers as the key. This meant that
   there would never be a cache hit and the cache woudl just accumulate massive
   numbers of PredictionContext 'objects'!

Bloody hell. Sometimes it is difficult to spot such glaring errors. This change
vastly reduces memory usage. The next commit will fix the visited context look up
which also suffers from the same problem.

Fixes: antlr#3934
It probably also fixes a ton of performance and memory usage problems, which
I have yet to test.

Signed-off-by: Jim.Idle <jimi@idle.ws>
 - Note, I think that this still needs work, but it is a lot better memory wise.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Some of the legacy code that tried to implement comparisons and hashing like Java was
just plain wrong. That stuff is buried deep in there and took a massive effort to
work out what was going wrong.

In the end, while the hash codes were OK for DFAState, the comparisons inherited from
the old code were just plain wrong for certain objects. With those corrected, there
is a massive improvement in performance all around.

I will push a PR for this stuff now, but I already see some massive potential gains
by getting rid of interfaces where we don't need them stopping the use of pointers everywhere
indiscrimiately.

Next task is going to be pure performance improvements until the Go runtime takes
its rightful place as the fastest implementation ;)

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
 - I will of course fix this in a follow up PR, but the test DropLoopEntryBranchInLRRule_4
   currently hangs. It is also disabled for many other runtimes, so I think it is fine to get
   this PR in and then follow up with a fix for this test.

Signed-off-by: Jim.Idle <jimi@idle.ws>
 - Removes the need to perform a `go mod tidy` for every test. This change
   causes `go mod tidy` to be run once, after which it caches the go.mod and
   go.sum files for use by the remaining tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
… flowcontrol - 50% performance improvement

  - Prior to this change, a recognition error was tracked by performing a panic(),
    which the generated code for rules would then use recover() to discover. However,
    recover() is not like catch(){} in Java and is expensive to run even if there is
    no panic() to find on the execution stack. Eliminating this and doing a simple check
    at the end of rule execution brings with it a massive performance improvement up to
    50% of CPU execution time. Now that collections and context caching is working correctly
    this is a significant improvement in execution time.

Signed-off-by: Jim.Idle <jimi@idle.ws>
@jimidle
Copy link
Collaborator Author

jimidle commented Mar 28, 2023

@parrt This PR is all ready to go mate! Phew!

@parrt
Copy link
Member

parrt commented Mar 28, 2023

This PR is all ready to go mate! Phew!
Hi! It looks like there are some merge conflicts according to GitHub

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 28, 2023

@parrt The PR says it is ready to merge. Perhaps you saw an earlier email?

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 28, 2023 via email

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 28, 2023

Now it says there are... GitHUb sometimes.

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 28, 2023

Now it says there are not any.

image

@ericvergnaud
Copy link
Contributor

No conflict here

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 28, 2023 via email

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 29, 2023

Looks good now @parrt

@parrt
Copy link
Member

parrt commented Mar 29, 2023

Unfortunately I've seen this before wear different people see different views. Check this out
Screenshot 2023-03-28 at 5 50 22 PM

@parrt parrt merged commit ce241de into antlr:dev Mar 29, 2023
@parrt
Copy link
Member

parrt commented Mar 29, 2023

merged manually using cmd-line. thanks, @jimidle !!!

@jimidle
Copy link
Collaborator Author

jimidle commented Mar 29, 2023

Yeah - I think this kind of thing happens when:

  • I submit a PR from one branch
  • That goes in fine
  • I pull up to my dev branch in my fork-
  • I rebase in to my other feature branch that I was working on
  • Submit the PR from that branch and it all goes haywire.

It's because of forks I think. I don't have this issue using git flow and having people submit from a non-fork branch

Anyway -it's done, and I will avoid a rebase from dev if possible.

@AkbaraliShaikh
Copy link

AkbaraliShaikh commented Apr 8, 2023

Hello @jimidle,

When are we planning to merge these changes to the master branch?

between which jar should be used to generate the code using the dev branch?

cc: @parrt

@jimidle
Copy link
Collaborator Author

jimidle commented Apr 8, 2023

Hello @jimidle,

When are we planning to merge these changes to the master branch?

between which jar should be used to generate the code using the dev branch?

cc: @parrt

Soon I hope. It will happen when @parrt calls for a new release. My current work is basically preventing him from calling that. But I think it is worth the wait for the end of next week, when I will be done with all my experiments on memory allocation/pressure and add a few more performance tweaks that will be good for well formed grammars.

I have pretty much concluded the investigation into ways we might address memory and essentially I am finding that the existing GC is better than anything we can do in user code space. Mainly because it is extremely difficult to work out exactly when certain structs are no longer referenced and can be reused without getting the GC itself to tell me.

So, I think I am done with memory work as of right now. I may come back to this after the next release and see if I can work out exactly where and when I can reuse structs. But in this release I have added diagnostics and stats that allow at least me to work out what things are causing slow parsing - it is always a poor grammar, but it is useful to know what parts of a bad grammar cause difficulties, in case there can be a few wins.

I will leave it to Terence to decide when the new release should happen. It is not a ten minute task I think.

@AkbaraliShaikh
Copy link

Hello @jimidle,
When are we planning to merge these changes to the master branch?
between which jar should be used to generate the code using the dev branch?
cc: @parrt

Soon I hope. It will happen when @parrt calls for a new release. My current work is basically preventing him from calling that. But I think it is worth the wait for the end of next week, when I will be done with all my experiments on memory allocation/pressure and add a few more performance tweaks that will be good for well formed grammars.

I have pretty much concluded the investigation into ways we might address memory and essentially I am finding that the existing GC is better than anything we can do in user code space. Mainly because it is extremely difficult to work out exactly when certain structs are no longer referenced and can be reused without getting the GC itself to tell me.

So, I think I am done with memory work as of right now. I may come back to this after the next release and see if I can work out exactly where and when I can reuse structs. But in this release I have added diagnostics and stats that allow at least me to work out what things are causing slow parsing - it is always a poor grammar, but it is useful to know what parts of a bad grammar cause difficulties, in case there can be a few wins.

I will leave it to Terence to decide when the new release should happen. It is not a ten minute task I think.

Okay, Thank you.

Between, I have tried using the dev branch for benchmarking my rule paring code:

go get github.com/antlr/antlr4/runtime/Go/antlr/v4@dev

Used antlr-4.12.0-complete.jar to generate the code,
But after the code is generated, getting the below error in the *_parser.go

parser/myrule_parser.go:1367:67: not enough arguments in call to p.GetInterpreter().AdaptivePredict
        have (antlr.TokenStream, number, antlr.ParserRuleContext)
        want (*antlr.BaseParser, antlr.TokenStream, int, antlr.ParserRuleContext)

Anything I'm missing here?

@jimidle
Copy link
Collaborator Author

jimidle commented Apr 9, 2023 via email

@jimidle jimidle deleted the feature/performance branch April 11, 2023 03:43
@ericvergnaud
Copy link
Contributor

ericvergnaud commented Apr 11, 2023 via email

@jimidle
Copy link
Collaborator Author

jimidle commented Apr 11, 2023

Hi, you need to build it, I’m afraid...

Actually you don't I guess. When the build checks run for the PR request, it does actually upload the built jar. But it is a little convoluted.

For this PR:

  • https://github.com/antlr/antlr4/actions/runs/4663531339
  • You can see that there are artifacts for the Tool. Because it is Java, you can download any of the _tool outputs.
  • You will get a zip download
  • Expand the Zip
  • Find the ANTLR tool directory, then look under the target directory and you will find the snapshot complete jar.

@AkbaraliShaikh
Copy link

AkbaraliShaikh commented Apr 11, 2023

@jimidle Here are the perf results for the master vs dev branch

Master Branch

go test -run=Bench -benchmem -bench=. -benchtime=60s
goos: darwin
goarch: arm64
pkg: source.golabs.io/asgard/spikes/rule-engine
BenchmarkParseRule-10                            4565505             16049 ns/op           12536 B/op        259 allocs/op
PASS
ok      source.golabs.io/asgard/spikes/rule-engine      222.331s

Dev Branch

go test -run=Bench -benchmem -bench=. -benchtime=60s
goos: darwin
goarch: arm64
pkg: source.golabs.io/asgard/spikes/rule-engine
BenchmarkParseRule-10                            4908742             15095 ns/op           12192 B/op        230 allocs/op
PASS
ok      source.golabs.io/asgard/spikes/rule-engine      218.251s

@jimidle
Copy link
Collaborator Author

jimidle commented Apr 11, 2023 via email

@AkbaraliShaikh
Copy link

AkbaraliShaikh commented Apr 11, 2023

@jimidle there was some mistake, I have updated the above results

@jimidle here are the above requested details which are used perf testing: https://github.com/AkbaraliShaikh/test

@jimidle
Copy link
Collaborator Author

jimidle commented Apr 11, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.