Skip to content

Allow path stitcher to work on SQLiteReader #291

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

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

hendrikvanantwerpen
Copy link
Collaborator

This PR makes changes to ForwardPartialPathStitcher and related types to add support for running the path stitcher directly on a SQLiteReader. With this change, the ForwardPartialPathStitcher is the one and only path building implementation.

Some changes that were made as part of this:

  • Rename Candidates to ForwardCandidates, which is in line with the ForwardPartialPathStitcher and would make it easier in the future if we ever get backward algorithms.
  • Add SQLReader::clear method for easier reuse of instances. It clears the cached data in the reader.
  • Extend ForwardCandidates trait with the reponsibility to manage access to the graph and partial path arena. As a result, the ForwardCandidates instance is the only thing going into the stitcher, and replaces the explicit StackGraph and PartialPaths arguments. This was necessary to allow the candidates implementation to lazy load data during stitching.
  • Thread ForwardCandidates errors through ForwardPartialPathStitcher, so that loading errors can be reported to the caller.

@hendrikvanantwerpen hendrikvanantwerpen self-assigned this Jun 30, 2023
@github-actions
Copy link

Performance Summary

Comparing base acb0fab with head ee936e1 on microsoft/[email protected]. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.530^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                   ::                                      
     |            #                   :                               : :     
     |          @@#       :: :      :::                               : :     
     |          @ #     : :  :::    : : : ::          @:              : ::    
     |      :   @ #     :::  ::     : : : :  @@      :@:              ::::    
     |     ::@@ @ #:::: :::  ::  :: : : :::  @  :@@:::@:  :::    : :  ::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   192.7
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.136^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                  ::                                       
     |            #                  :                                  :     
     |            #                  :                                  :     
     |           @#                 ::                                  :     
     |           @#      ::         ::                                : :     
     |           @#      :  :::     :: : @            :               : :     
     |      ::   @#      : :::      :: : @   :       ::    ::         :::     
     |      :    @# :: : : :::   :: :: ::@ :::     ::::    :    :     :::     
     |     ::   :@#:: :: : :::   :  :: ::@ : : :: :: ::   :: :: ::  ::::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   181.4

@hendrikvanantwerpen hendrikvanantwerpen marked this pull request as ready for review June 30, 2023 14:06
@hendrikvanantwerpen hendrikvanantwerpen requested a review from a team as a code owner June 30, 2023 14:06
@github-actions
Copy link

Performance Summary

Comparing base acb0fab with head a552756 on microsoft/[email protected]. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.530^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                   ::                                      
     |            #                   :                               : :     
     |          @@#       :: :      :::                               : :     
     |          @ #     : :  :::    : : : ::          @:              : ::    
     |      :   @ #     :::  ::     : : : :  @@      :@:              ::::    
     |     ::@@ @ #:::: :::  ::  :: : : :::  @  :@@:::@:  :::    : :  ::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   192.7
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.576^           #                                                            
     |           #                                                            
     |           #                                                            
     |           #                                                            
     |           #                                                            
     |           #         ::                                                 
     |          @#         :          :                                       
     |          @#        ::          :                                 :     
     |          @#        ::          :                                ::     
     |          @#        :: :::      :    :           :               :::    
     |    @@@@ :@#@@  :  ::: ::       :  : :           :              ::::    
     |    @ @  :@#@ :::::::: ::    : ::  :@:      :: :::   ::@        ::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   204.8

@github-actions
Copy link

Performance Summary

Comparing base acb0fab with head 2a5b45f on microsoft/[email protected]. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.530^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                   ::                                      
     |            #                   :                               : :     
     |          @@#       :: :      :::                               : :     
     |          @ #     : :  :::    : : : ::          @:              : ::    
     |      :   @ #     :::  ::     : : : :  @@      :@:              ::::    
     |     ::@@ @ #:::: :::  ::  :: : : :::  @  :@@:::@:  :::    : :  ::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   192.7
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.136^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                  @                                        
     |            #                  @                                : :     
     |            #       :          @                                : :     
     |            #       :  :       @                                : :     
     |            #       :: ::      @  :::         :@:              :: :@    
     |     @ @@   #      ::: ::     :@  :::         :@:    :         :: :@    
     |     @:@  ::# :::  ::: ::  :: :@ :@:::    ::  :@:  : :     : : :: :@:   
     |     @:@ :: #@:::  ::::::  @: :@ :@::::   :::::@:  ::: ::::: ::::::@::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   180.0

@github-actions
Copy link

github-actions bot commented Jul 4, 2023

Performance Summary

Comparing base acb0fab with head 8a3834c on microsoft/[email protected]. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.530^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                   ::                                      
     |            #                   :                               : :     
     |          @@#       :: :      :::                               : :     
     |          @ #     : :  :::    : : : ::          @:              : ::    
     |      :   @ #     :::  ::     : : : :  @@      :@:              ::::    
     |     ::@@ @ #:::: :::  ::  :: : : :::  @  :@@:::@:  :::    : :  ::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   192.7
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.561^           #                                                            
     |           #                                                            
     |           #                                                            
     |           #                                                            
     |           #                                                            
     |           #         :                                                  
     |           #         :          :                                       
     |           #         :   ::     :                                 ::    
     |           #       :::  ::      :                                 :     
     |         ::#       : :  ::      :    :          ::            ::: :     
     |    ::@@ : #@@    :: :  ::      :    :          :             : : :     
     |    : @  : #@ @:  :: :  ::   @  :  ::: ::  ::  ::   ::    : ::: ::: : : 
   0 +----------------------------------------------------------------------->Gi
     0                                                                   204.1

@github-actions
Copy link

github-actions bot commented Jul 4, 2023

Performance Summary

Comparing base acb0fab with head b3bc09a on microsoft/[email protected]. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.530^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                   ::                                      
     |            #                   :                               : :     
     |          @@#       :: :      :::                               : :     
     |          @ #     : :  :::    : : : ::          @:              : ::    
     |      :   @ #     :::  ::     : : : :  @@      :@:              ::::    
     |     ::@@ @ #:::: :::  ::  :: : : :::  @  :@@:::@:  :::    : :  ::::::  
   0 +----------------------------------------------------------------------->Gi
     0                                                                   192.7
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- test/src/compiler
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    GB
1.530^            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |            #                                                           
     |          @@#        ::        ::                                       
     |          @ #        :         :                                  :     
     |          @ #       :: ::      :     :                            ::    
     |          @ #       :: : ::    :  ::::         : ::            :::::    
     |      ::  @ # : :  ::: : :     :  : ::  ::     :::             :: ::    
     |     :: : @ #::::::::: : : :   :  : ::  :   :: :::  :::   :: :::: :::   
   0 +----------------------------------------------------------------------->Gi
     0                                                                   196.7

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

Performance Summary

Comparing base f8477c5 with head db92a36 on typescript_benchmark benchmark. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- base/data/typescript_benchmark
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    MB
715.8^                                                                    #   
     |                                                  @@                #   
     |                                                  @               ::#   
     |                            @@                   :@               : #   
     |                            @                  :::@               : #   
     |                    :      :@                  : :@              :: #:  
     |                   ::    :::@                 :: :@              :: #:  
     |                   ::  ::: :@        ::       :: :@ :            :: #:: 
     |                   ::::: : :@       ::        :: :@ :           ::: #:: 
     |                  @::: : : :@ @@ :::::     :  :: :@ :           ::: #:: 
     |                  @::: : : :@ @ ::: :: @@  ::::: :@ :     @ ::  ::: #:: 
     |                  @::: : : :@ @ ::: :: @ :::: :: :@ : ::  @:: @@::: #:: 
   0 +----------------------------------------------------------------------->Gi
     0                                                                   52.82
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- head/data/typescript_benchmark
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    MB
715.8^                                                                     #  
     |                                                   @                 #  
     |                                                 @@@                 #  
     |                                                 @@@               ::#: 
     |                                                 @@@               ::#: 
     |                           :@@                 ::@@@               ::#: 
     |                    :    :::@                  : @@@               ::#: 
     |                    :  ::: :@         :        : @@@::           ::::#::
     |                    :  @ : :@       :::        : @@@:            : ::#::
     |                  @@:::@ : :@  :::::: :      ::: @@@:            : ::#::
     |                  @ :: @ : :@  : :: : :      : : @@@:         :::: ::#::
     |                  @ :: @ : :@  : :: : :::::@@: : @@@: ::::@@:::: : ::#::
   0 +----------------------------------------------------------------------->Gi
     0                                                                   51.89

graph: &StackGraph,
partials: &mut PartialPaths,
db: &mut Db,
candidates: &mut C,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only API suggestion I can think of is to consider if this could/should be mut candidates: C instead. I think you're always passing in a mut ref to a temporary, in which case you can just pass in that temporary directly. It probably doesn't matter from a codegen perspective, though, so if you consider this shape to be more understandable I'm also good with keeping it as-is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, but the SQLiteReader implements Candidates directly, and would be moved (and lost) by this change. So I'm going to leave it as-is.

This is to keep consistent with the `ForwardPartialPathStitcher` and it
keeps to option open to introduce `Backward` versions in the future.
These changes add support for using `ForwardPartialPathStitcher`
directly on a `SQLiteReader` (besides the already supported graph edges
and `Database`). This required pushing the `StackGraph` + `PartialPaths`
+ `ToAppendable` values into the `ForwardCandidates` trait, to allow the
candidates implementation to lazily load data during the stitching
process.
@github-actions
Copy link

Performance Summary

Comparing base 0fcb846 with head 233e827 on typescript_benchmark benchmark. For details see workflow artifacts. Note that performance is tested on the last commits with changes in stack-graphs, not on every commit.

Before
--------------------------------------------------------------------------------
Command:            base/target/release/tree-sitter-stack-graphs-typescript index -D base.sqlite --max-file-time=30 --hide-error-details -- base/data/typescript_benchmark
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 base-perf-results/perf.out
--------------------------------------------------------------------------------


    MB
715.8^                                                                   #    
     |                                                 @                 #:   
     |                                               @@@               :@#:   
     |                           @                   @@@               :@#:   
     |                           @                   @@@               :@#:   
     |                    :    ::@                  :@@@ :            ::@#:   
     |                   ::  ::::@                  :@@@ :            ::@#: : 
     |                   ::::::::@        :       :::@@@::           :::@#::: 
     |                   ::::::::@   :   ::       : :@@@::           :::@#::: 
     |                  @::::::::@  ::@::::    :  : :@@@::          ::::@#::: 
     |                 @@::::::::@  ::@: ::  : : :: :@@@::   @ : :: ::::@#::: 
     |                 @@::::::::@  ::@: ::::::: :: :@@@:: ::@::::::::::@#::::
   0 +----------------------------------------------------------------------->Gi
     0                                                                   54.49
After
--------------------------------------------------------------------------------
Command:            head/target/release/tree-sitter-stack-graphs-typescript index -D head.sqlite --max-file-time=30 --hide-error-details -- head/data/typescript_benchmark
Massif arguments:   --massif-out-file=perf.out
ms_print arguments: --x=72 --y=12 head-perf-results/perf.out
--------------------------------------------------------------------------------


    MB
715.8^                                                                   #    
     |                                                @                  #    
     |                                                @                  #    
     |                                             :::@                ::#    
     |                                             :: @                ::#   :
     |                   ::    :@@                 :: @   ::           ::#   :
     |                  ::    ::@                 ::: @  ::            ::#  ::
     |                  ::  ::::@        ::       ::: @::::          ::::# :::
     |                  ::  : ::@       ::        ::: @: ::          : ::#::::
     |                  :: :: ::@   : ::::     : :::: @: ::         :: ::#::::
     |                 @:: :: ::@   ::: ::  @  : :::: @: ::     :   :: ::#::::
     |                 @:: :: ::@  :::: :: :@:::::::: @: :: ::@ :@@ :: ::#::::
   0 +----------------------------------------------------------------------->Gi
     0                                                                   55.28

@hendrikvanantwerpen hendrikvanantwerpen merged commit 496c6ff into main Sep 13, 2023
@hendrikvanantwerpen hendrikvanantwerpen deleted the sql-based-stitching branch September 13, 2023 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants