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

Optimizer - condense constants into a single string #139

Closed
tom-leys opened this issue Sep 4, 2024 · 10 comments
Closed

Optimizer - condense constants into a single string #139

tom-leys opened this issue Sep 4, 2024 · 10 comments

Comments

@tom-leys
Copy link

tom-leys commented Sep 4, 2024

When the compiler (or previous optimization steps in this case) outputs this MLOG

print "Reactor "
print 1
print " in emergency shutdown mode\n"

The optimizer should condense it to

print "Reactor 1 in emergency shutdown mode\n"

This was the result of unrolling a loop which calls a function (now with a constant) and printfs in that function.

The full example is here #136

@cardillan
Copy link
Owner

Print merging merges non-string constants only on aggressive optimization level. The default optimization level is basic in the web app and aggressive in the command-line compiler.

Adding #set optimization = aggressive at the beginning of your program does the trick for the web application.

(Note: I'm not very happy with the way the optimization levels are implemented right now - it seems it generates a lot of confusion. I think it needs some overhaul, but I don't have a clear idea for a better solution at the moment.)

@tom-leys
Copy link
Author

tom-leys commented Sep 5, 2024

(Note: I'm not very happy with the way the optimization levels are implemented right now - it seems it generates a lot of confusion. I think it needs some overhaul, but I don't have a clear idea for a better solution at the moment.)

How about the compiler output contains hints

Hint: 10 optimiszations did not run, add #set optimization = aggressive to run them. Alternatively turn on optimizations x,y,z by adding #turn on one optimization

@tom-leys
Copy link
Author

tom-leys commented Sep 5, 2024

Also, I didn't install the command line compiler because you make it sound quite hard - Java, a database, docker ...

If you had a package with a compiled command line compiler and clear instructions on how to get a JVM (link to a suitable open one) that would have been more attractive and would have reduced your server load.

Also a watch command (though you'd probably need to output to a file in that case) would be useful. Watch, compile, show errors and a keybind that copies the last compile output to the clipboard might work.

@cardillan
Copy link
Owner

How about the compiler output contains hints

Hint: 10 optimiszations did not run, add #set optimization = aggressive to run them. Alternatively turn on optimizations x,y,z by adding #turn on one optimization

That would be nice. On the other hand, it is not always easy to figure out whether the aggressive optimization would actually be effective, so the code would become more complex and harder to maintain.

I'll probably add optimization level selection to the web app, plus a generic hint that aggressive optimization might produce better code when run on basic. That'll hopefully draw enough attention to it.

If you had a package with a compiled command line compiler and clear instructions on how to get a JVM (link to a suitable open one) that would have been more attractive and would have reduced your server load.

Yeah, I should do that. Good idea!

Also a watch command (though you'd probably need to output to a file in that case) would be useful. Watch, compile, show errors and a keybind that copies the last compile output to the clipboard might work.

Currently the compiler has a switch that copies the resulting code to the clipboard when the compilation is successful.

Watch does sound like a better alternative, but I don't know Linux that well. If you wished to provide some supporting tools or scripts, I'll gladly include them, but I won't be able to support them.

@cardillan
Copy link
Owner

@tom-leys I've just published a new release, which includes compiled command line tool and installation instructions in the readme. I'd be glad to hear any feedback you might have :)

@tom-leys
Copy link
Author

Wonderful!

I'm currently taking a break from writing mindcode, preparing to start a new contract shortly so studying Go instead to add it to my very long list of known languages. I'll let you know once I've tried it out (but it might be a month or more). In the meantime I hope other authors benefit from your efforts.

I really appreciate your rapid support.

@tom-leys
Copy link
Author

Just to add, I reviewed your documentation and that sounds ideal. Assuming it works as described that is perfect.

@cardillan
Copy link
Owner

Thanks and good luck with your new contract! :)

@tom-leys
Copy link
Author

Thanks @cardillan :)

@cardillan
Copy link
Owner

All the ideas from this thread have been implemented in 2.3.0.

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

No branches or pull requests

2 participants