Skip to content

Conversation

@nezda
Copy link
Contributor

@nezda nezda commented May 22, 2023

[#36] allow changing almost everything in Config using System Properties

  • note: used underscores instead of periods used in the joni.debug* options
  • had to tweak Search.java for the change to compile

…operties

* note: used underscores instead of periods used in the joni.debug* options
@headius
Copy link
Member

headius commented May 22, 2023

I love it! Will review and chat with other maintainers.

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

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

Looks great overall! Just a few minor changes needed.

int tail = targetEnd - 1;
int tlen1 = tail - targetP;
if (USE_SUNDAY_QUICK_SEARCH) {
tlen1 = tail - targetP;
Copy link
Member

Choose a reason for hiding this comment

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

Is this fixing a separate bug? If so we should move it to another PR because it's not config-related.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when I changed USE_SUNDAY_QUICK_SEARCH to be initialized from system property it no longer compiled

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project joni: Compilation failure: Compilation failure:
[ERROR] /Users/nezda/code/joni.git/src/org/joni/Search.java:[438,59] variable tlen1 might not have been initialized
[ERROR] /Users/nezda/code/joni.git/src/org/joni/Search.java:[446,59] variable tlen1 might not have been initialized

so I tried to fix.

Copy link
Member

Choose a reason for hiding this comment

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

I pinged @enebo to look at this too.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, it was constant propagated since those interface fields are essentially static finals

@headius headius added this to the 2.1.49 milestone May 22, 2023
@lopex
Copy link
Contributor

lopex commented May 22, 2023

It will disable constant propagations for those flags, I dont have an opinion on it though

@nezda
Copy link
Contributor Author

nezda commented May 22, 2023

It will disable constant propagations for those flags, I don't have an opinion on it though

Seems like conservative thing to do is preserve whatever performance constant propagation gets us and just don't let USE_SUNDAY_QUICK_SEARCH be configurable (and revert my change to `Search.java). Doesn't preclude it being made configurable in the future.

@lopex
Copy link
Contributor

lopex commented May 22, 2023

Oh, I was referring to all flags, those affecting parser shouldnt matter though.
But for example this one - USE_CEC (combination explostion check) was never used and tested and is a part of very hot code - opFail().
@headius, @enebo some of the other flags are part of hot paths in stack manipulations and bytecode interpreter - do you think it will affect performance by much?

@nezda
Copy link
Contributor Author

nezda commented May 22, 2023

It is interesting an implicitly final variable initialized in that way stops being treated as a constant (but it seems clear something is going on related to that since code failed to compile without modification). I suppose final local variables could be introduce to ferry in values from those "constants" in that interface?

@lopex
Copy link
Contributor

lopex commented May 22, 2023

static finals where a direct translation for c #ifdef macros - I dont recall anything that could be a substitute for that in java.

@nezda
Copy link
Contributor Author

nezda commented May 22, 2023

I always thought final variables were basically equivalent to c #ifdef. I think this is my first counter-example.

I could introduce a Configuration object with all final fields initialized in a constructor which would have benefit different instances within same jvm could have different configurations.

@lopex
Copy link
Contributor

lopex commented May 22, 2023

There's at least two types of finals in java, static finals complete disapear from bytecode. So, dead branches will also make the bytecode smaller.

@headius
Copy link
Member

headius commented May 22, 2023

Yeah, @lopex is right that this will prevent javac from eliminating code paths that were impossible to reach with literal static final values. That's why that sunday search code you patched suddenly started failing; with the original true value the uncompilable path was never followed and javac did not error.

I think the utility of making these configurable is worth any possible bytecode size increase here, even though it may tweak the inlining decisions of various JVMs. It should not generally affect performance when the same things inline as before, but some methods may cross size thresholds that prevent them from being trivially inlinable after this change.

If we could come up with a good way to audit which methods are affected by this, we could always move the conditional bodies out to separate static methods so they are small and don't impact the size of the original. There would be an additional inline that has to happen, so we'd have to weigh that against shrinking methods. We can make some determination by benchmarking expression matches that hit such methods heavily.

Personally, I would be surprised if this ends up being observable, and since there's no way to make these configurable without breaking the javac dead code optimization it may just be a price we have to accept (if it really has a cost).

@headius
Copy link
Member

headius commented May 22, 2023

I would probably say we should just merge and then look at doing some benchmarking to find any performance regressions. We want these things to be configurable to make joni more flexible (to users other than JRuby also), so there may just be additional work necessary to find any slowdowns and deal with them.

@nezda
Copy link
Contributor Author

nezda commented May 23, 2023

For what it's worth, I concur with vote to merge this. I'd also be surprised if this had any significant negative performance consequence.

@enebo
Copy link
Member

enebo commented May 23, 2023

One followup to places where we do decide something is performance sensitive. We can split some of these things into separate types so we end up with more copies of some part of the code at the benefit of not having these ifdef sections. I also think this should merge and if possible we can see if we really see any perf differences.

@headius headius merged commit 9dc7935 into jruby:master May 23, 2023
@headius
Copy link
Member

headius commented May 23, 2023

Merged! We are debating some other fixes for release but otherwise we'll push this out soon.

@headius
Copy link
Member

headius commented May 23, 2023

Moved to 2.2.0 because we're also landing some API changes (and this deprecates and changes some API as well).

@enebo enebo mentioned this pull request Aug 4, 2023
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.

4 participants