Skip to content

Add cppia? - #1127

Draft
HEIHUAa wants to merge 22 commits into
CodenameCrew:mainfrom
HEIHUAa:cppia
Draft

HEIHUAa wants to merge 22 commits into
CodenameCrew:mainfrom
HEIHUAa:cppia

Conversation

@HEIHUAa

@HEIHUAa HEIHUAa commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Given that no one replied to the previous issue at #1106, I tried to do some work on it first.

The currently implemented content is as follows:
DiscordUtil is compatible with scriptable
hscript can normally load cppia from the path mods//source/Class.cppia via import

That's right, only these. I currently don't know how to handle the entire compilation process for cppia.


It is also planned to add support for directly loading and using .cppia files in mods/<mod>/data/states/.

@HEIHUAa
HEIHUAa marked this pull request as draft September 22, 2026 02:23
@r6915ee

r6915ee commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Unless there's something I don't exactly understand about CPPIA here, perhaps this could be done instead by extending the Script class and adding the appropriate constructor usage to Script? I think that would allow doing this without complicating the overall code, alongside allowing this to be used almost everywhere HScript is allowed in.

@HEIHUAa

HEIHUAa commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Unless there's something I don't exactly understand about CPPIA here, perhaps this could be done instead by extending the Script class and adding the appropriate constructor usage to Script? I think that would allow doing this without complicating the overall code, alongside allowing this to be used almost everywhere HScript is allowed in.

Extending the Script class is something I have indeed thought about. I think this is also a feature it should ultimately have, but the current implementation approach may still need discussion.

@Raltyro

Raltyro commented Sep 22, 2026

Copy link
Copy Markdown
Member

cppia could be like scripts too me thinks, but gets preloaded once when the mod first loads in MainState

@HEIHUAa

HEIHUAa commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

cppia could be like scripts too me thinks, but gets preloaded once when the mod first loads in MainState

After testing, it can be loaded anywhere in real time, but once loaded, it stays in memory forever and seemingly cannot be cleared. However, the memory used by JIT is not large and can be ignored. Also, some places may still reference certain code within the cppia, so clearing it directly from memory could cause a crash.


I just tested that cppia can be replaced in real time and new cppia can be loaded.

@HEIHUAa

HEIHUAa commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

I roughly know how to write scriptable cppia now. I might add a CppiaMacro to convert things like the script-like Parent. Also, Script.onCall can directly call the corresponding function in cppia, which would support all the call triggers supported by hscript scripts, except this operation requires one reflection.

@HEIHUAa

HEIHUAa commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

After more accurate testing, I found that cppia is actually not close to native speed at all — it is nearly 10–50 times slower than native. Still, I think it's worth it, since it's much faster than hscript, which is 150–500 times slower.

@Raltyro

Raltyro commented Oct 9, 2026

Copy link
Copy Markdown
Member

Would be a good addition to CNE if it works really well compared to CNE's hscript-improved

@Raltyro Raltyro added the type:enhancement New feature or request label Oct 9, 2026
@Raltyro

Raltyro commented Oct 9, 2026

Copy link
Copy Markdown
Member

I'm not sure yet but can cppia implement custom classes, typedefs, etc? and would it be comfortable for you if we move the branch to CodenameCrew's?

@HEIHUAa

HEIHUAa commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm not sure yet but can cppia implement custom classes, typedefs, etc? and would it be comfortable for you if we move the branch to CodenameCrew's?

cppia is about 10–30× faster than hscript-improved, but there is still some gap compared to native.

Previous tests:

Operation cppia
String operations ×1.5
Field access ×9
Arithmetic ×11.8
Array operations ×17.8
Method calls ×24.7
Recursive calls ×39.7

The so-called JIT in cppia actually barely speeds up any operation. It only speeds up method calls by nearly 30% and recursive calls by 9.3×. It has almost no improvement — everything is within the margin of error.

For hscript-improved, let me find the tests from when I optimized the interpreter.

Compared to native:

Operation hscript-improved
Arithmetic ×190
Method calls ×100
Recursive calls ×4100

In actual testing, it supports almost all native operations. Except for untyped __cpp__, cpp.Lib.load, and runtime macros, everything else seems to work.

If there is one downside, it might be EXE bloat: it will inflate the current ~67 MB EXE file to nearly ~98 MB. You can actually see this from the files in the Actions of my repo.

@Raltyro

Raltyro commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Oof, it might not be really helpful in this case then if it only does a little of performance and requires more of a headache to work with, and a bloat... especially with the hscript-improved still getting a performance upgrades later on

@Raltyro Raltyro added the status:invalid This doesn't seem right label Oct 9, 2026
@HEIHUAa

HEIHUAa commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Oof, it might not be really helpful in this case then if it only does a little of performance and requires more of a headache to work with, and a bloat... especially with the hscript-improved still getting a performance upgrades later on

In practice, I think one of the more useful things about cppia is that you can compile almost an entire library—one that does not include untyped __cpp__, cpp.Lib.load, or runtime macros—into a single cppia and run it in real time.

@HEIHUAa

HEIHUAa commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

I searched around and it seems I found a repository that can compile Hx to cppia in real time (https://github.com/MeguminBOT/hxscript). I think it might be worth taking a look at that one.

@Raltyro

Raltyro commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

This is a good project that we have seen actually in the development discord server, but unfortunately this creator doesn't really like our project and they probably don't allow us to use this.

@HEIHUAa

HEIHUAa commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

That's a shame — it really is a good project.

@HEIHUAa

HEIHUAa commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Until I find a way to use cppia without increasing the binary size, I think it's highly likely that I won't be making any more updates.

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

Labels

status:invalid This doesn't seem right type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants