Skip to content

[Translation] Improved the performance of the lint:xliff command #27653

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
Jun 20, 2018

Conversation

javiereguiluz
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27564
License MIT
Doc PR -

As suggested by @stof I extracted the schema validation logic from XliffFileLoader to reuse it in the lint:xliff command. The validation is now instantaneous, so the command is blazing fast!

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

some random comments :)

$this->validateSchema($xliffVersion, $dom, $this->getSchema($xliffVersion));
$xliffVersion = XliffUtils::getVersionNumber($dom);
$errors = XliffUtils::validateSchema($dom);
if (0 !== count($errors)) {
Copy link
Member

Choose a reason for hiding this comment

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

if ($errors = XliffUtils::validateSchema($dom)) {

@@ -110,7 +111,6 @@ private function validate($content, $file = null)
}

libxml_use_internal_errors(true);

Copy link
Member

Choose a reason for hiding this comment

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

should be reverted and maybe done on 2.8/3.4?

$errors[] = array(
'line' => $xmlError->line,
Copy link
Member

Choose a reason for hiding this comment

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

indentation fix worth a PR on 2.8/3.4 I suppose also

* Provides some utility methods for XLIFF translation files, such as validating
* their contents according to the XSD schema.
*
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
Copy link
Member

Choose a reason for hiding this comment

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

not sure about this sorry :(

@nicolas-grekas nicolas-grekas changed the title Improved the performance of the lint:xliff command [Translation] Improved the performance of the lint:xliff command Jun 20, 2018
{
/**
* Gets xliff file version based on the root "version" attribute.
* Defaults to 1.2 for backwards compatibility.
Copy link
Member

Choose a reason for hiding this comment

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

there should be an empty phpdoc line after the short description

* Provides some utility methods for XLIFF translation files, such as validating
* their contents according to the XSD schema.
*
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
Copy link
Member

Choose a reason for hiding this comment

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

I suggest tagging this class as @internal for now

if (!$isValid) {
libxml_disable_entity_loader($disableEntities);

return static::getXmlErrors($internalErrors);
Copy link
Member

Choose a reason for hiding this comment

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

accessing private static methods must be done using self::, not static. Otherwise, when extending the class, PHP tries to access it using the child class, which won't work (same for all other static calls to a private method)


$isValid = @$dom->schemaValidateSource(static::getSchema($xliffVersion));
if (!$isValid) {
libxml_disable_entity_loader($disableEntities);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we also reset the usage of internal errors before returning here ?

We could even use try/finally for that to ensure it always happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure about this. I'm using the exact same code as before. I'd prefer to not change that logic because it's unrelated to this PR.

return $errorsAsString;
}

private static function getSchema($xliffVersion): string
Copy link
Member

Choose a reason for hiding this comment

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

string typehint ?


foreach ($xmlErrors as $error) {
$errorsAsString .= sprintf("[%s %s] %s (in %s - line %d, column %d)\n",
LIBXML_ERR_WARNING == $error['level'] ? 'WARNING' : 'ERROR',
Copy link
Member

Choose a reason for hiding this comment

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

strict comparison should be used

@javiereguiluz
Copy link
Member Author

Fixed everything. Thanks for the review.

@fabpot
Copy link
Member

fabpot commented Jun 20, 2018

Thank you @javiereguiluz.

@fabpot fabpot merged commit e53bf58 into symfony:master Jun 20, 2018
fabpot added a commit that referenced this pull request Jun 20, 2018
…ff command (javiereguiluz)

This PR was squashed before being merged into the 4.2-dev branch (closes #27653).

Discussion
----------

[Translation] Improved the performance of the lint:xliff command

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27564
| License       | MIT
| Doc PR        | -

As suggested by @stof I extracted the schema validation logic from XliffFileLoader to reuse it in the `lint:xliff` command. The validation is now instantaneous, so the command is blazing fast!

Commits
-------

e53bf58 [Translation] Improved the performance of the lint:xliff command
nicolas-grekas added a commit that referenced this pull request Aug 8, 2018
This PR was merged into the 4.1 branch.

Discussion
----------

[Translation] fix perf of lint:xliff command

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27564
| License       | MIT
| Doc PR        | -

#27653 has been merged on master as an improvement, but the perf issue is a killer.
Our CI spends 1 minutes on just a few translation test cases.
Only 4.1 has this behavior. That's a bug.

Commits
-------

02c69b1 [Translation] fix perf of lint:xliff command
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants