10000 Prevent unnecessary runtime validation for newtype generated macros by edmorley · Pull Request #331 · heroku/libcnb.rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prevent unnecessary runtime validation for newtype generated macros #331

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 1 commit into from
Feb 22, 2022

Conversation

edmorley
Copy link
Member
@edmorley edmorley commented Feb 21, 2022

Adjusts the newtype generated compile-time validation macros so that they don't perform redundant validation at runtime, given that the value was already validated at compile time.

In cases where only compile-time validation is being performed (for example exec.d scripts), this results in significant reduction in binary size (1.7MB -> 0.4MB in a release+stripped binary), due to no longer needing the fancy-regex dependency at runtime.

A new_unchecked() method was added, so that the types (whose backing string is intentionally private) can be constructed by the code generated by the macro (which will exist outside of the module). The name was based on:
https://doc.rust-lang.org/std/index.html?search=new_unchecked

Fixes #330.
GUS-W-10727850.

@edmorley edmorley self-assigned this Feb 21, 2022
@edmorley edmorley requested review from Malax and hone February 21, 2022 12:28
@edmorley edmorley force-pushed the edmorley/newtype-macro-fix branch from 875151e to 3afb542 Compare February 21, 2022 12:43
@edmorley edmorley added this to the libcnb 0.6.0 milestone Feb 21, 2022
Adjusts the newtype generated compile-time validation macros so that they
don't perform redundant validation at runtime, given that the value was
already validated at compile time.

In cases where only compile-time validation is being performed (for example
`exec.d` scripts), this results in significant reduction in binary size
(1.7MB -> 0.4MB in a release+stripped binary), due to no longer needing
the `fancy-regex` dependency at runtime..

A `new_unchecked()` method was added, so that the types (whose backing
string is intentionally private) can be constructed by the code generated
by the macro (which will exist outside of the module). The name was based on:
https://doc.rust-lang.org/std/index.html?search=new_unchecked

Fixes #330.
GUS-W-10727850.
@edmorley edmorley force-pushed the edmorley/newtype-macro-fix branch from 3afb542 to 8e8fe32 Compare February 21, 2022 18:11
Copy link
Member
@Malax Malax left a comment

Choose a reason for hiding this comment

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

Nice. :)

@edmorley edmorley merged commit d36fac7 into main Feb 22, 2022
@edmorley edmorley deleted the edmorley/newtype-macro-fix branch February 22, 2022 09:59
@edmorley edmorley added performance slim buildpacks Things that affect the size of the compiled binaries or packaged buildpacks labels Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libcnb-data slim buildpacks Things that affect the size of the compiled binaries or packaged buildpacks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Newtype macros for compile-time validation also perform validation at runtime
2 participants
0