Skip to content

Conversation

KristofferC
Copy link
Owner

@KristofferC KristofferC commented Jul 31, 2025

This outsources the table printing to PrettyTables.jl. I initially used an LLM to do the first implementation and then fixed things up manually. I want to do some further improvements to the display and allow for more customization so using an external table renderer seems like a good idea. Right now (with PrettyTables), the output looks like:

───────────────────────────────────────────────────────────────────────────────
                       Time (tot / % meas)         Allocations  (tot / % meas) 
                           6.30s / 45.4%                  296MiB / 26.6%       
                                                                               
 Section      ncalls    time    %tot     avg          alloc     %tot       avg 
───────────────────────────────────────────────────────────────────────────────
 sleep           101   1.23s   42.8%  12.1ms        16.3KiB     0.0%      165B 
 nest 2            1   703ms   24.6%   703ms        1.17KiB     0.0%   1.17KiB 
   level 2.2       1   402ms   14.0%   402ms           112B     0.0%      112B 
   level 2.1       1   301ms   10.5%   301ms           112B     0.0%      112B 
 throwing          1   502ms   17.5%   502ms           528B     0.0%      528B 
 nest 1            1   401ms   14.0%   401ms        1.89KiB     0.0%   1.89KiB 
   level 2.2       1   202ms    7.1%   202ms           112B     0.0%      112B 
   level 2.1       3  96.3ms    3.4%  32.1ms           624B     0.0%      208B 
 randoms           1  30.8ms    1.1%  30.8ms        78.5MiB   100.0%   78.5MiB 
 Main.foo          1  0.00ns    0.0%  0.00ns          0.00B     0.0%     0.00B 
 funcdef           1  0.00ns    0.0%  0.00ns          0.00B     0.0%     0.00B 
───────────────────────────────────────────────────────────────────────────────

compared to the previous:

────────────────────────────────────────────────────────────────────────
                               Time                    Allocations      
                      ───────────────────────   ────────────────────────
  Tot / % measured:        9.01s /  32.1%            244MiB /  34.2%    

Section       ncalls     time    %tot     avg     alloc    %tot      avg
────────────────────────────────────────────────────────────────────────
sleep            101    1.22s   42.0%  12.1ms   16.6KiB    0.0%     168B
nest 2             1    704ms   24.3%   704ms   1.17KiB    0.0%  1.17KiB
  level 2.2        1    402ms   13.9%   402ms      112B    0.0%     112B
  level 2.1        1    302ms   10.4%   302ms      112B    0.0%     112B
throwing           1    500ms   17.3%   500ms      528B    0.0%     528B
nest 1             1    400ms   13.8%   400ms   1.80KiB    0.0%  1.80KiB
  level 2.2        1    202ms    7.0%   202ms      112B    0.0%     112B
  level 2.1        3   95.6ms    3.3%  31.9ms      336B    0.0%     112B
randoms            1   75.5ms    2.6%  75.5ms   83.4MiB  100.0%  83.4MiB
funcdef            1   42.0ns    0.0%  42.0ns     0.00B    0.0%    0.00B
Main.foo           1   0.00ns    0.0%  0.00ns     0.00B    0.0%    0.00B

One thing I liked about the previous implementation is that if the width of the terminal gets too small, it starts making the sections smaller:

julia> to
─────────────────────────────────────────────────────────────────────
                            Time                    Allocations      
                   ───────────────────────   ────────────────────────
 Tot / % measured:      53.7s /   5.4%            245MiB /  34.0%    

Section    ncalls     time    %tot     avg     alloc    %tot      avg
─────────────────────────────────────────────────────────────────────
sleep         101    1.22s   42.0%  12.1ms   16.6KiB    0.0%     168B
nest 2          1    704ms   24.3%   704ms   1.17KiB    0.0%  1.17KiB
  level...      1    402ms   13.9%   402ms      112B    0.0%     112B
  level...      1    302ms   10.4%   302ms      112B    0.0%     112B

With PrettyTables it instead starts to truncate the rightmost columns:

─────────────────────────────────────────────────────────────────────
                       Time (tot / % meas)         Allocations  (to ⋯
                           7.10s / 40.3%             296MiB / 26.6% ⋯
                                                                    ⋯
 Section      ncalls    time    %tot     avg          alloc     %to ⋯
─────────────────────────────────────────────────────────────────────
 sleep           101   1.22s   42.8%  12.1ms        16.3KiB     0.0 ⋯
 nest 2            1   703ms   24.6%   703ms        1.17KiB     0.0 ⋯
   level 2.2       1   402ms   14.1%   402ms           112B     0.0 ⋯
   level 2.1       1   301ms   10.5%   301ms           112B     0.0 ⋯
 throwing          1   502ms   17.6%   502ms           528B     0.0 ⋯
 nest 1            1   401ms   14.0%   401ms        1.80KiB     0.0 ⋯
   level 2.2       1   202ms    7.1%   202ms           112B     0.0 ⋯
   level 2.1       3  96.4ms    3.4%  32.1ms           336B     0.0 ⋯
 randoms           1  29.8ms    1.0%  29.8ms        78.5MiB   100.0 ⋯
 Main.foo          1  42.0ns    0.0%  42.0ns          0.00B     0.0 ⋯
 funcdef           1  0.00ns    0.0%  0.00ns          0.00B     0.0 ⋯
─────────────────────────────────────────────────────────────────────

@ronisbr, is there a possibility of choising a specific column that gets narrowed instead of narrowing the table to the right? Also, right now I was using (what I think is) the v3 API but that is not released yet, right?

@KristofferC
Copy link
Owner Author

This is a screenshot of the current render:

image

the narrow gray lines under e.g. 121s / 2.4% does not appear when you copy paste the text here for example, so not sure where that comes from. Also, I don't think I said that some of the sections should be gray? Maybe that is just some PrettyTables default.

@ronisbr
Copy link

ronisbr commented Jul 31, 2025

Hi @KristofferC!

is there a possibility of choising a specific column that gets narrowed instead of narrowing the table to the right?

Not currently, but I think I can implement it! We can specify one column and the algorithm will try to shrink that first by setting its maximum size before cutting the right part. I will try to do this before releasing v3!

Also, right now I was using (what I think is) the v3 API but that is not released yet, right?

Yes, these features like merge column labels are only available in v3. It is unreleased but there is only one feature missing to fully support DataFrames.jl printing as it is today. I am almost sure I will be able to tag v3 this weekend if nothing goes wrong.

the narrow gray lines under e.g. 121s / 2.4% does not appear when you copy paste the text here for example, so not sure where that comes from.

By default, PrettyTables.jl asks for the terminal to print merged labels with underlines. That's why you cannot see them when you copy the text. Do you want a feature to allow the algorithm to draw a line only on the bottom of merged cells?

Also, I don't think I said that some of the sections should be gray? Maybe that is just some PrettyTables default.

Yes! All column labels besides the first line are drawn in gray to match the previous behavior. If you want to change, just add something like: style = TextTableStyle(; column_label = Crayon(), merged_column_label = Crayon()).

@IanButterworth
Copy link
Collaborator

IanButterworth commented Jul 31, 2025

Seems like a reasonable direction to go in.

I played with adding what could be an optional column and some experimental color coding here #193

I mention that just to factor in potential ideas like that in case this would restrict those kind of features at all. (not that they're approved or really being actively developed)

@KristofferC
Copy link
Owner Author

Thanks for all the answers @ronisbr. There is no rush with this PR so take whatever time you need with v3 :).

@IanButterworth, I don't think this should be any hindrance for stuff like that, if anything, it would make new features like that easier since one won't have to mess with my hacky table printing code.

@ronisbr
Copy link

ronisbr commented Aug 3, 2025

Hi @KristofferC !

I added an option to the text backend called shrinkable_data_column. In this case, you can specify a data column that will be shrunk before any display cropping.

Captura de Tela 2025-08-02 às 21 28 47 Captura de Tela 2025-08-02 às 21 28 59

Can you please test and tell me if it is working as you want or if I need to make any modifications?

@KristofferC
Copy link
Owner Author

Will do, I am on a tenting trip right now so will take a couple of days for me to be able to test.

@KristofferC
Copy link
Owner Author

It works quite nice!

julia> show(to; compact=true)
Total measured:  91.1s /  254MiB

─────────────────────────────────────────────────────
 Sect…  ncalls    time    %tot         alloc    %tot 
─────────────────────────────────────────────────────
 sleep     101   1.22s   42.7%       13.2KiB    0.0% 
 nest…       1   704ms   24.7%       1.69KiB    0.0% 
   le…       1   402ms   14.1%          112B    0.0% 
   le…       1   302ms   10.6%          112B    0.0% 
 thro…       1   502ms   17.6%          432B    0.0% 
 nest…       1   399ms   14.0%       2.02KiB    0.0% 
   le…       1   201ms    7.1%          112B    0.0% 
   le…       3  96.2ms    3.4%          336B    0.0% 
 rand…       1  26.0ms    0.9%       78.8MiB  100.0% 
 func…       1   375ns    0.0%         0.00B    0.0% 
 foo         1   167ns    0.0%         0.00B    0.0% 
─────────────────────────────────────────────────────

Although perhaps I would want to be able to set a minimum width of it, if I make it quite small I get:

julia> show(to; compact=true)
Total measured:   122s /  254MiB

─────────────────────────────────────────────
 …  ncalls    time    %tot         alloc    ⋯
─────────────────────────────────────────────
 …     101   1.22s   42.7%       13.2KiB    ⋯
 …       1   704ms   24.7%       1.69KiB    ⋯
 …       1   402ms   14.1%          112B    ⋯
 …       1   302ms   10.6%          112B    ⋯
 …       1   502ms   17.6%          432B    ⋯
 …       1   399ms   14.0%       2.02KiB    ⋯
 …       1   201ms    7.1%          112B    ⋯
 …       3  96.2ms    3.4%          336B    ⋯
 …       1  26.0ms    0.9%       78.8MiB  1 ⋯
 …       1   375ns    0.0%         0.00B    ⋯
 …       1   167ns    0.0%         0.00B    ⋯
─────────────────────────────────────────────

which at that point I rather see a bit of the section column and have it truncate on the right for the rest.

@ronisbr
Copy link

ronisbr commented Aug 9, 2025

Awesome! I just added the option shrinkable_column_minimum_width so that you can define a minimum width of that column. Let me know if everything is working please!

@KristofferC
Copy link
Owner Author

Works great!

──────────────────────────────────────────────────────
                   Time (tot / % meas)         Alloc ⋯
                       10.7s / 26.9%            235M ⋯
                                                     ⋯
 Section  ncalls    time    %tot     avg          al ⋯
──────────────────────────────────────────────────────
 sleep       101   1.21s   42.3%  12.0ms        13.2 ⋯
 nest 2        1   704ms   24.5%   704ms        1.69 ⋯
   leve…       1   402ms   14.0%   402ms           1 ⋯
   leve…       1   302ms   10.5%   302ms           1 ⋯
 throwi…       1   502ms   17.5%   502ms           1 ⋯
 nest 1        1   400ms   13.9%   400ms        2.02 ⋯
   leve…       1   202ms    7.0%   202ms           1 ⋯
   leve…       3  96.2ms    3.3%  32.1ms           3 ⋯
 randoms       1  50.0ms    1.7%  50.0ms        78.8 ⋯
 funcdef       1   125ns    0.0%   125ns          0. ⋯
 foo           1  83.0ns    0.0%  83.0ns          0. ⋯
──────────────────────────────────────────────────────

@ronisbr
Copy link

ronisbr commented Aug 14, 2025

Awesome! I just need to implement one last feature (somewhat complicated) and v3 is ready to go!

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.

3 participants