Skip to content

Switch to a tail-call based dispatch loop instead of switch-inside-while - #5

Open
jwmerrill wants to merge 18 commits into
mainfrom
tail-call-dispatch
Open

Switch to a tail-call based dispatch loop instead of switch-inside-while#5
jwmerrill wants to merge 18 commits into
mainfrom
tail-call-dispatch

Conversation

@jwmerrill

@jwmerrill jwmerrill commented May 9, 2023

Copy link
Copy Markdown
Owner

Inspired by https://blog.reverberate.org/2021/04/21/musttail-efficient-interpreters.html

Unfortunately, the Zig compiler doesn't yet support tail calls when targeting WASM, so merging this would break WASM support.

@jwmerrill

Copy link
Copy Markdown
Owner Author

Benchmark results at various stages of this work:

cf7c6c7

test/benchmark/equality.lox
  min: 6458 mean: 6530
test/benchmark/binary_trees.lox
  min: 3290 mean: 3374
test/benchmark/properties.lox
  min: 704 mean: 766
test/benchmark/invocation.lox
  min: 484 mean: 564
test/benchmark/fib.lox
  min: 1761 mean: 1847
test/benchmark/trees.lox
  min: 3863 mean: 3929
test/benchmark/instantiation.lox
  min: 1540 mean: 1585
test/benchmark/method_call.lox
  min: 328 mean: 374
test/benchmark/zoo.lox
  min: 504 mean: 633

0610706

test/benchmark/equality.lox
  min: 5015 mean: 5114
test/benchmark/binary_trees.lox
  min: 3199 mean: 3237
test/benchmark/properties.lox
  min: 713 mean: 750
test/benchmark/invocation.lox
  min: 555 mean: 563
test/benchmark/fib.lox
  min: 1550 mean: 1629
test/benchmark/trees.lox
  min: 3521 mean: 3683
test/benchmark/instantiation.lox
  min: 1508 mean: 1549
test/benchmark/method_call.lox
  min: 317 mean: 350
test/benchmark/zoo.lox
  min: 580 mean: 624

aec43dc

test/benchmark/equality.lox
  min: 3698 mean: 4035
test/benchmark/binary_trees.lox
  min: 2721 mean: 2864
test/benchmark/properties.lox
  min: 504 mean: 630
test/benchmark/invocation.lox
  min: 399 mean: 461
test/benchmark/fib.lox
  min: 1382 mean: 1430
test/benchmark/trees.lox
  min: 2768 mean: 2943
test/benchmark/instantiation.lox
  min: 1524 mean: 1575
test/benchmark/method_call.lox
  min: 226 mean: 268
test/benchmark/zoo.lox
  min: 432 mean: 511

a5859ce

test/benchmark/equality.lox
  min: 3183 mean: 3327
test/benchmark/binary_trees.lox
  min: 2794 mean: 2812
test/benchmark/properties.lox
  min: 570 mean: 595
test/benchmark/invocation.lox
  min: 439 mean: 446
test/benchmark/fib.lox
  min: 1284 mean: 1522
test/benchmark/trees.lox
  min: 2749 mean: 2909
test/benchmark/instantiation.lox
  min: 1446 mean: 1484
test/benchmark/method_call.lox
  min: 234 mean: 243
test/benchmark/zoo.lox
  min: 450 mean: 465

aec43dc

test/benchmark/equality.lox
  min: 2769 mean: 2880
test/benchmark/binary_trees.lox
  min: 2701 mean: 2792
test/benchmark/properties.lox
  min: 531 mean: 551
test/benchmark/invocation.lox
  min: 412 mean: 418
test/benchmark/fib.lox
  min: 1186 mean: 1249
test/benchmark/trees.lox
  min: 2674 mean: 2798
test/benchmark/instantiation.lox
  min: 1490 mean: 1538
test/benchmark/method_call.lox
  min: 236 mean: 248
test/benchmark/zoo.lox
  min: 421 mean: 453

e23d6ae

test/benchmark/equality.lox
  min: 2329 mean: 2480
test/benchmark/binary_trees.lox
  min: 2635 mean: 2816
test/benchmark/properties.lox
  min: 510 mean: 527
test/benchmark/invocation.lox
  min: 393 mean: 413
test/benchmark/fib.lox
  min: 1158 mean: 1256
test/benchmark/trees.lox
  min: 2614 mean: 2737
test/benchmark/instantiation.lox
  min: 1392 mean: 1429
test/benchmark/method_call.lox
  min: 216 mean: 231
test/benchmark/zoo.lox
  min: 428 mean: 440

772db3d

test/benchmark/equality.lox
  min: 2315 mean: 2372
test/benchmark/binary_trees.lox
  min: 2569 mean: 2623
test/benchmark/properties.lox
  min: 460 mean: 489
test/benchmark/invocation.lox
  min: 374 mean: 381
test/benchmark/fib.lox
  min: 1118 mean: 1213
test/benchmark/trees.lox
  min: 2554 mean: 2697
test/benchmark/instantiation.lox
  min: 1378 mean: 1407
test/benchmark/method_call.lox
  min: 201 mean: 210
test/benchmark/zoo.lox
  min: 362 mean: 377

0de7303

test/benchmark/equality.lox
  min: 2189 mean: 2250
test/benchmark/binary_trees.lox
  min: 2591 mean: 2681
test/benchmark/properties.lox
  min: 431 mean: 460
test/benchmark/invocation.lox
  min: 341 mean: 343
test/benchmark/fib.lox
  min: 895 mean: 938
test/benchmark/trees.lox
  min: 2704 mean: 2813
test/benchmark/instantiation.lox
  min: 1246 mean: 1288
test/benchmark/method_call.lox
  min: 199 mean: 201
test/benchmark/zoo.lox
  min: 355 mean: 370

@jwmerrill

Copy link
Copy Markdown
Owner Author

This is a big performance improvement across all benchmarks, but for some reason, clox from the crafting interpreters book is still faster on most benchmarks.

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.

1 participant